在iframe中发生点击时如何触发事件?

时间:2022-08-26 09:09:40

I want to catch clicks that occur anywhere in an iframe. I can not directly access the iframe because it contains content from another domain. So how would I do that with jQuery? Somehow calculate if the click occurred in the area of the iframe? The iframe should stay totally accessible as it contains links etc.

我想抓住iframe中任何地方发生的点击。我无法直接访问iframe,因为它包含来自其他域的内容。那我怎么用jQuery呢?以某种方式计算点击是否发生在iframe区域? iframe应该完全可访问,因为它包含链接等。

1 个解决方案

#1


2  

This is impossible due to the Same origin policy. jQuery cannot magically circumvent the browser environment.

由于同源政策,这是不可能的。 jQuery无法神奇地规避浏览器环境。

You may wish to implement a same-domain proxy (example in php) that passes the target site's html through to your iframe. You didn't mention what server-side technology you are using so I cannot be more specific.

您可能希望实现将目标网站的html传递给iframe的同域代理(例如php)。你没有提到你正在使用的服务器端技术,所以我不能更具体。

#1


2  

This is impossible due to the Same origin policy. jQuery cannot magically circumvent the browser environment.

由于同源政策,这是不可能的。 jQuery无法神奇地规避浏览器环境。

You may wish to implement a same-domain proxy (example in php) that passes the target site's html through to your iframe. You didn't mention what server-side technology you are using so I cannot be more specific.

您可能希望实现将目标网站的html传递给iframe的同域代理(例如php)。你没有提到你正在使用的服务器端技术,所以我不能更具体。