Search code examples
javascriptmousemoveevent-passthrough

Receive mousemove events from iframe, too


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?


Solution

  • You can do that quite easily if the document in the iframe is on the same document.domain.

    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.

    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.