Detect Click into Iframe using JavaScript

前端 未结 21 2715
轻奢々
轻奢々 2020-11-22 03:06

I understand that it is not possible to tell what the user is doing inside an iframe if it is cross domain. What I would like to do is track if the user clicke

21条回答
  •  忘掉有多难
    2020-11-22 03:16

    This is small solution that works in all browsers even IE8:

    var monitor = setInterval(function(){
        var elem = document.activeElement;
        if(elem && elem.tagName == 'IFRAME'){
            clearInterval(monitor);
            alert('clicked!');
        }
    }, 100);
    

    You can test it here: http://jsfiddle.net/oqjgzsm0/

提交回复
热议问题