Detect Click into Iframe using JavaScript

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

    http://jsfiddle.net/QcAee/406/

    Just make a invisible layer over the iframe that go back when click and go up when mouseleave event will be fired !!
    Need jQuery

    this solution don't propagate first click inside iframe!

    $("#invisible_layer").on("click",function(){
    		alert("click");
    		$("#invisible_layer").css("z-index",-11);
    
    });
    $("iframe").on("mouseleave",function(){
    		$("#invisible_layer").css("z-index",11);
    });
    iframe {
        width: 500px;
        height: 300px;
    }
    #invisible_layer{
      position: absolute;
      background-color:trasparent;
      width: 500px;
      height:300px;
    }
    
    

提交回复
热议问题