Skip to content

Instantly share code, notes, and snippets.

@karlazz
Last active April 29, 2021 22:40
Show Gist options
  • Save karlazz/0bac0b59e9b5c7b7797b1601a30ba12f to your computer and use it in GitHub Desktop.
Save karlazz/0bac0b59e9b5c7b7797b1601a30ba12f to your computer and use it in GitHub Desktop.
Detect onclick event in iframe
var clickIframe = window.setInterval(checkFocus, 100);
var i = 0;
function checkFocus() {
if(document.activeElement == document.getElementById("ifr")) {
console.log("clicked "+(i++));
window.focus();
}
}
// https://stackoverflow.com/questions/29337304/how-to-detect-a-click-inside-of-an-iframe-cross-domain-aka-prevent-click-frau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment