Created
June 13, 2017 14:03
-
-
Save dmail/899a0023537fb36a1111b8100c2b62ef to your computer and use it in GitHub Desktop.
Bubbling iframe events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bubbleIframeEvents = (iframe, document) => { | |
const iframeWindow = iframe.contentWindow | |
iframeWindow.addEventListener( | |
'mousemove', | |
(event) => { | |
const boundingClientRect = iframe.getBoundingClientRect() | |
const fakeEvent = new CustomEvent( | |
'mousemove', | |
{ | |
bubbles : true, | |
cancelable : false, | |
} | |
) | |
fakeEvent.clientX = event.clientX + boundingClientRect.left | |
fakeEvent.clientY = event.clientY + boundingClientRect.top | |
iframe.dispatchEvent(fakeEvent) | |
} | |
) | |
iframeWindow.addEventListener( | |
'mousedown', | |
(event) => { | |
const fakeEvent = new CustomEvent( | |
'mousedown', | |
{ | |
bubbles : true, | |
cancelable : false, | |
} | |
) | |
iframe.dispatchEvent(fakeEvent) | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment