mbarkhau
mbarkhau

Reputation: 8479

How to detect the visibility of a cross-domain Iframe?

There are companies that claim to be able to detect the visibility of an iframe without access to the embedding page. Two I found are spider.io and comscore, both of which say their technology is patent pending. Any ideas how they might be doing this?

Upvotes: 3

Views: 1708

Answers (2)

Joe Coulson
Joe Coulson

Reputation: 71

This question is really old so you probably have an answer by now but see below for some ways that x-domain iframe visibility can be calculated.

In browsers that support Flash and optimise the refresh rate if the flash object is on vs off screen you can place flash pixels at strategic areas in the iframe and measure the refresh rates to calculate how much of the iframe is visible.

In IE8+ (which doesn't optimise Flash refresh rates) you can operate a similar detection method by using document.elementFromPoint at the same strategic locations to detect visibility. Thus will only work in IE however as all other browsers return values in x-domain iframes without taking the viewport in to account.

In FF there is the window.mozInnerScreenY/X properties that can be useful for helping to calculate visibility.

I won't go into further detail (because it is too much effort on a mobile) but they are the three main ways of doing it currently.

In the future the will be the new IntersectionObserver that is in the next version of Chrome so will hopefully be generally available before Flash finally bites the dust.

Upvotes: 5

runlevel0
runlevel0

Reputation: 2993

Easy, by tagging the iframe. There's nothing 'patentable' on that.

You can set a 1 pixel GIF "tag" on the iframe or use a so called "soft-tag", this can BTW track any element of any page, not just an iframe independently from the embedding page. The code used is inline javascript.

I am however not sure if this feature is available outside comScore's DaX platform. You can always contact their support department.

Upvotes: 0

Related Questions