捕获iframe jQuery中的所有事件并复制 [英] Catch all events in iframe jQuery and replicate

查看:174
本文介绍了捕获iframe jQuery中的所有事件并复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题:



我有一个iframe显示任何网页(不一定由我开发)。
在这个页面上可能会附加事件(大概我不知道的)。



我如何动态拦截这些事件并存储以备以后复制? / p>

例如:
假设当鼠标移过某个div时,它会改变颜色。
我想确保当您触发将颜色更改为div的事件时,将注册所有A系列信息,允许我(无用户交互)稍后复制它。



想法?对于录音和后续复制

解决方案

简短的回答是:你不能



如果您位于不同的域,则无法访问页面上的JavaScript的任何网页的文档对象,如果您说任何网页,因为同源政策。您将需要IFRAME中的网站与您的脚本配合来实现这一点,这不会发生在任何网页。



同一域上的IFRAME

如果您的网页位于同一个域,那么您可以访问通过为每个想要捕获的事件添加一个侦听器来实现IFRAMEs body元素此处。对于身体,向上冒泡的所有活动都是可行的。所以如果你有事件被阻止向上冒泡到身体,他们将不会被捕捉到这个解决方案。

  jQuery( '#website body')。on('click mouseover mouseout',function(event){
console.log(event.type);
});

假设您有一个标有网站的IFRAME 你可以通过上面列出的空格来列出你想要的事件。该示例捕获单击 mousover mouseout 。 p>

也许这更接近你想要的东西?


this is the question:

I have an iframe that displays any web page (not necessarily developed by me). On this page may be attached events (which presumably I do not know).

how can I dynamically intercepting these events and store them for later replicate?

for example: suppose that when the mouse moves over a certain div it changes color. I would like to make sure that when you trigger the event that would change color to the div it is "registered" with all A series of information that will allow me (without user interaction) to replicate it at a later time.

ideas? for both the recording and subsequent replication

解决方案

The short answer is: you cannot.

You cannot access the document object of "any web page" with JavaScript on your page if it is on a different domain, which I assume if you say "any web page", because of the Same Origin Policy. You would need the website in the IFRAME to cooperate with your script to achieve this, which will not happen with "any web page".

IFRAME on same domain
If your web page is on the same domain then you can access the events of the IFRAMEs body element by adding a listener for every event you want to catch like described here. This is possible for all events that bubble up to the body. So if you have Events that are prevented from bubbling upwards to the body, they will not be catched with this solution.

jQuery('#website body').on('click mouseover mouseout', function(event) {
    console.log(event.type);
});

Assuming you have an IFRAME with the id website you can catch the events you wish by listing them separated with spaces as above. The example catches click, mousover and mouseout.

Maybe this is closer to what you want?

这篇关于捕获iframe jQuery中的所有事件并复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆