问题描述
我有一个javascript应用程序,它为文档添加了一个mousemove监听器。问题:
当鼠标移动到iframe上时,不会调用该函数。
I have a javascript app, whichs adds a mousemove listener to the document. Problem:When the mouse is moved over an iframe, the function is NOT called.
有没有办法将这些事件传递给根文档?
Is there a way to pass through such events to the root document?
推荐答案
如果iframe中的文档位于同一个document.domain中,则可以非常轻松地完成此操作。
You can do that quite easily if the document in the iframe is on the same document.domain.
如果你有相同的document.domain,你也必须在iframe中设置一个mousemove监听器,并将值传递给父页面。
If you have the same document.domain, you will have to set a mousemove listener in the iframe as well and pass the values out to the parent page.
如果文档不在同一个document.domain上,它会变得非常复杂,你需要iframes页面来运行设置mousemove事件监听器的javascript本身。然后您可以按照此处所述进行跨框架通信:
If the documents are not on the same document.domain it becomes quite a bit mroe complex, and you will need the iframes page to run javascript itself that sets the mousemove event listener. and then you can do cross frame communication as described here: http://softwareas.com/cross-domain-communication-with-iframes
否则,由于浏览器执行的原始政策相同,您运气不佳。
Otherwise you are out of luck due to the same origin policy that browsers enforce.
这篇关于从iframe接收mousemove事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!