I was faced with a situation where I had to track clicks on a button on social networks pulled through an iframe. When you click the button, a new window opens. Here is my solution:
var iframeClick = function () { var isOverIframe = false, windowLostBlur = function () { if (isOverIframe === true) { // DO STUFF isOverIframe = false; } }; jQuery(window).focus(); jQuery('#iframe').mouseenter(function(){ isOverIframe = true; console.log(isOverIframe); }); jQuery('#iframe').mouseleave(function(){ isOverIframe = false; console.log(isOverIframe); }); jQuery(window).blur(function () { windowLostBlur(); }); }; iframeClick();
source share