Accuratly catch clicks on an iframe

笑着哭i 提交于 2019-12-12 02:58:29

问题


I have an ad iframe being written onto my page dynamically. The advert inside may have another iframe itself and will "suck" click events through into it so cannot track them easily. I've used this great plugin by @Vince in the past:

https://github.com/finalclap/iframeTracker-jquery

which seems to work fine until the window this is all running in IS ITSELF an iframe and focus is somewhere on the outermost page. I can see it getting the rollover/rollout events but it doesn't get the click unless focus is somewhere inside the first iframe's window.

Has anyone found a solid way to do this? Thanks in advance if anyone can help.


回答1:


One way to do this without writing lots of javascript detection click logic would be to have the advert on the page and the clickable link links back to your site. Updates a counter and then redirects them to the target page.

The above is just a different way of thinking about it. Plus it will still work if they don't have javascript enabled.




回答2:


I think you can't do that using Javascript because of the same origin policy.

My iframeTracker plugin uses a crafty workaround to detect click on iframe, based on mouse and focus events, that simply doesn't work with multiple nested iframes.



来源:https://stackoverflow.com/questions/25891050/accuratly-catch-clicks-on-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!