在iframe中发生点击时如何触发事件? [英] How to fire an event when click occurs in iframe?

查看:86
本文介绍了在iframe中发生点击时如何触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

由于同源政策。 jQuery无法神奇地规避浏览器环境。

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

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

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.

这篇关于在iframe中发生点击时如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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