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.
You can read the contents in an iframe easily via jQuery ( $(iframe). contents() ) if the domain of the webpage which contains the iframe is same as the domain of the web-page opened in iframe . The microservice responsible for uploading file was on different domain and the main app is on another domain.
In short, to check if a page is in an iframe, you need to compare the object's location with the window object's parent location. If they are equal, then the page is not in an iframe; otherwise, a page is in an iframe.
Can I hide content inside an iframe from an external domain? Yes totally doable. Once you assign the parameter to a var, you could then do anything you want… like a hide() on an element.
A cross domain inline frame (iframe) is a type of web technology that can be used to embed a small portion of one website within a larger "parent" page hosted on a different domain.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With