How to fire an event when click occurs in iframe?

2019-07-17 23: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.

回答1:

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.