检测使用JavaScript点击进入Iframe [英] Detect Click into Iframe using JavaScript

查看:230
本文介绍了检测使用JavaScript点击进入Iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,如果是跨域,则无法告诉用户在 iframe 内的内容。我想要做的是跟踪用户是否在 iframe 中完全点击了。我想象一个场景,在 iframe 之上有一个看不见的 div div 然后将click事件传递给 iframe

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 clicked at all in the iframe. I imagine a scenario where there is an invisible div on top of the iframe and the the div will just then pass the click event to the iframe.

这样的事情可能吗?如果是,那我该怎么办呢? iframes 是广告,因此我无法控制所使用的代码。

Is something like this possible? If it is, then how would I go about it? The iframes are ads, so I have no control over the tags that are used.

推荐答案


这样的事情可能吗?

Is something like this possible?

没有。你所能做的就是检测进入iframe的鼠标,并且当它返回时可能(虽然不可靠)(即试图找出在其他地方传递广告的指针与在ad)。

No. All you can do is detect the mouse going into the iframe, and potentially (though not reliably) when it comes back out (ie. trying to work out the difference between the pointer passing over the ad on its way somewhere else versus lingering on the ad).


我想象一个场景,iframe顶部有一个不可见的div,然后div将通过点击iframe的事件。

I imagine a scenario where there is an invisible div on top of the iframe and the the div will just then pass the click event to the iframe.

不,没有办法伪造点击事件。

Nope, there is no way to fake a click event.

通过捕捉mousedown,您可以阻止原始点击进入iframe。如果您可以确定何时按下鼠标按钮,您可以尝试将不可见的div移开,以便点击将通过...但是也没有事件在mousedown之前触发。

By catching the mousedown you'd prevent the original click from getting to the iframe. If you could determine when the mouse button was about to be pressed you could try to get the invisible div out of the way so that the click would go through... but there is also no event that fires just before a mousedown.

您可以尝试猜测,例如通过查看指针是否已经停止,猜测点击可能即将到来。但这完全不可靠,如果你失败了,你就会失去一次点击。

You could try to guess, for example by looking to see if the pointer has come to rest, guessing a click might be about to come. But it's totally unreliable, and if you fail you've just lost yourself a click-through.

这篇关于检测使用JavaScript点击进入Iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆