Skip to content

Instantly share code, notes, and snippets.

@dmail
Created June 13, 2017 14:03
Show Gist options
  • Save dmail/899a0023537fb36a1111b8100c2b62ef to your computer and use it in GitHub Desktop.
Save dmail/899a0023537fb36a1111b8100c2b62ef to your computer and use it in GitHub Desktop.
Bubbling iframe events
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