Detect Click into Iframe using JavaScript

前端 未结 21 2558
轻奢々
轻奢々 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:35

    This works for me on all browsers (included Firefox)

    https://gist.github.com/jaydson/1780598

    https://jsfiddle.net/sidanmor/v6m9exsw/

    var myConfObj = {
      iframeMouseOver : false
    }
    window.addEventListener('blur',function(){
      if(myConfObj.iframeMouseOver){
        console.log('Wow! Iframe Click!');
      }
    });
    
    document.getElementById('idanmorblog').addEventListener('mouseover',function(){
       myConfObj.iframeMouseOver = true;
    });
    document.getElementById('idanmorblog').addEventListener('mouseout',function(){
        myConfObj.iframeMouseOver = false;
    });

提交回复
热议问题