0

Is there a way to check, FROM WITHIN an iframe, whether the page in the iframe is in the 3rd party parent's browser viewport?

For instance, in this example, the answer is no, because the content in the iframe is positioned out of the viewport.

<body>
<div style="position: fixed; left: -1000px;">
<iframe id="iframeID" width="200" height="200" src="http://domainNotSameAsParent.com"></iframe>
</div>          
</body>
Shan Lim
  • 63
  • 2
  • 6

1 Answers1

0

I guessing based on "http://domainNotSameAsParent.com" that the iframe content and the main page aren't being served from the same origin. This will obviously lead to issues with the Same Origin Policy.

The same origin policy prevents a document or script loaded from one origin from getting or setting properties of a document from another origin. This policy dates all the way back to Netscape Navigator 2.0.

Basically if the iframe content is not from the same origin as the page you probably won't be able to check to see if the iframe is in the viewport.

If you're really determined to do this and you have access to both domains you may want to check:
Ways to circumvent the same-origin policy

But it is probably going to take way more time and effort than you really want to spend on something like this.

Community
  • 1
  • 1
apaul
  • 16,092
  • 8
  • 47
  • 82