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.