How to fire an event when click occurs in iframe?

2019-07-17 23:25发布

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.

1条回答
做自己的国王
2楼-- · 2019-07-17 23:35

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

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.

查看更多
登录 后发表回答