微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 使用Invisible div检测Click Inside IFrame

我仔细阅读了这篇文章.
Detect Click into Iframe using JavaScript

但是,我仍然看到人们做过类似的事情.请告诉我该怎么做.

一位开发人员告诉我:

You Could put a transparent DIV on top of the IFRAME. You size that
DIV to the same size or bigger than the IFRAME. And with a higher
z-index CSS property.

Then when you click on the IFRAME,the DIV receives the event.

But as the world is not perfect,Now you lost the ability to click
inside the IFRAME.

但我对div并不是很好,并希望学习如何做到这一点.
谢谢

附:它涉及跨域或外来域Iframing.

解决方法

如果我明白你在这里问的是什么:

jsFiddle

// PLACE OVERLAY OVER EACH IFRAME
var W=0,H=0,X=0,Y=0;
$(".iframe").each(function(i,el){
   W = $(el).width();
   H = $(el).height();
   X = $(el).position().left;
   Y = $(el).position().top;
   $(this).after('<div class="overlay" />');
    $(this).next('.overlay').css({
        width: W,height: H,left: X,top: Y        
    });
});

// TRACK MOUSE POSITIONS (the overlay will prevent clicks on iframe page)
var mx = 0,my = 0;
$('.overlay').on('mousemove click',function(e){
    mx = e.clientX - $(this).position().left;
    my = e.clientY - $(this).position().top;

    if(e.type==='click'){
        alert('clicked at: X='+mx+' Y='+my)
    }        
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐