Skip to content

Instantly share code, notes, and snippets.

@vidaaudrey
Forked from jaydson/gist:1780598
Created January 8, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidaaudrey/94d39955c6d4f0db22e6c1fe298b1a53 to your computer and use it in GitHub Desktop.
Save vidaaudrey/94d39955c6d4f0db22e6c1fe298b1a53 to your computer and use it in GitHub Desktop.
How to detect a click event on a cross domain iframe
var myConfObj = {
iframeMouseOver : false
}
window.addEventListener('blur',function(){
if(myConfObj.iframeMouseOver){
console.log('Wow! Iframe Click!');
}
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseover',function(){
myConfObj.iframeMouseOver = true;
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseout',function(){
myConfObj.iframeMouseOver = false;
});
@gusdewa
Copy link

gusdewa commented Jun 25, 2020

This works, but it does not trigger the actual click on the iframe itself.
How to trigger both (blur on parent and click on iframe) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment