简体   繁体   中英

How to detect if an element is visible within an iframe that is on a cross domain parent

Just as the question states, I have an iframe that is on a cross domain parent. I need to trigger an event if that content is scrolled into view or already in view on page load. Normal checks for distance from top/side of page and viewport height/width don't seem to work as they measure the page within the iframe itself.

I cannot edit/add anything on the parent page to enable this functionality, everything must be within the iframe itself.

The reason behind this is to record whether content has ever had the chance to be viewed by the user or if it was loaded out of view and kept there.

There are companies who provide this service for advertising, but as far as finding out how it is actually done, well it seems to be one of the dark arts.

Any help would be greatly appreciated.

EDIT: Two examples of the companies I spoke of who offer this service.

  1. View the first tick under (4) http://www.doubleverify.com/what-is-verification/
  2. First thing they state they can do on the right hand side http://adxpose.com/home.page

spider.io does this probably using browser timing attacks. there is a video on their page:

http://www.spider.io/viewability/

here is a nice report on how some browser timing attacks work: http://www.contextis.com/documents/2/Browser_Timing_Attacks.pdf

Simple answer is, you can't .

You have no way to access a cross-domain iframe ( DOM or window object ) with ECMAscript because of the Same Origin Policy.

doubleverify and adxpose use "offline" techniques to determine if the ad was visible or not, it doesn't happen on the page view. If they did it through Javascript, all you would have to do is look at one of their pixels to see how it works.

Are you sure those examples are exclusively iframe based? Maybe they need to add some javascript to the parent Window.

If you really need this, and 100% accuracy is not needed, I would try some time based techniques on the assumption that most browser will optimize graphical work happening out of view.

Being realistic I don't think it would be possible to get good results with that techniques in a reasonable time or expecting a general robust cross-browser solution. It would be quite fun though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM