Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 839
Vendrad Avatar asked Apr 02 '12 13:04

Vendrad


People also ask

How do I read Cross domain iframe content?

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.

How do you know if an element is in iframe?

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?

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.

Is iframe cross domain?

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.


2 Answers

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

like image 81
hereandnow78 Avatar answered Oct 20 '22 01:10

hereandnow78


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.

like image 20
jAndy Avatar answered Oct 20 '22 01:10

jAndy