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?
Can we add event listener in iframe? You can track this event inside your iframe by using the script below, which adds an event listener to catch the sent message once the ad is displayed to the user.
The mousemove event is fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside it.
Every mouse move over an element triggers that event. click. Triggers after mousedown and then mouseup over the same element if the left mouse button was used.
Put pointer-events: none;
in the styles for the frame.
I was having this problem myself and found this solution works great and is so simple!
You should look through combining parent document
event binding with document.getElementById('iFrameId').contentDocument
event, witch allows you to get access to iFrame content elements.
https://stackoverflow.com/a/38442439/2768917
function bindIFrameMousemove(iframe){
iframe.contentWindow.addEventListener('mousemove', function(event) {
var clRect = iframe.getBoundingClientRect();
var evt = new CustomEvent('mousemove', {bubbles: true, cancelable: false});
evt.clientX = event.clientX + clRect.left;
evt.clientY = event.clientY + clRect.top;
iframe.dispatchEvent(evt);
});
};
bindIFrameMousemove(document.getElementById('iFrameId'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With