Determine if iframe is displayed on screen

I have an iframe that loads into external sites from which I cannot paste code. What I would like to determine from my iframe (another domain) is if the iframe is currently in the browser's viewing area (or if it scrolls from the page).

Is there any way to do this? Since I do not believe that I can access the properties of the scroll height and viewport of the parent page (due to the cross domain), if I am not mistaken.

thanks

+4
source share
2 answers

No, this is not possible because you cannot access the document of the parent domain. This is necessary to determine the position of the iframe element. You can get the user's screen size, but more on that. Your iframe may be invisible and you cannot tell. Excuse me!

+4
source

I know this is an old question, but a new API has been released from Chrome that could answer your question about the latest versions of Chrome (22+)

InteractionObserver you can find it here: https://github.com/WICG/IntersectionObserver

There is a polyfill that is being developed (the same repo), but it will not work from iframe afaik only if the script is on the parent web page.

For other browsers, they have several dark ways to do this based on a temporary attack, this article explains it pretty well: http://www.contextis.com/documents/2/Browser_Timing_Attacks.pdf

0
source

All Articles