I use iframes in my news aggregation web app. While I am careful to always credit and link publishers, I also respect those who chose to block iframes (by not implementing sneaky workarounds). My question is how I can automatically detect whether iframes will be blocked, given the URL of the external page in question. So far i am using this code:
//get external html
$p = file_get_contents($this->scrape_ready_url);
//check for blocker
$pattern1 = "/window\.self.{1,10}window\.top/";
$s1 = preg_match($pattern1, $p);
//check for blocker2
$pattern2 = "/window\.top.{1,10}window\.self/";
$s2 = preg_match($pattern2, $p);
//condition response
if ($s1 === 1 || $s2 === 1) {
$this->frame = "blocked";
} else {
$this->frame = "not_blocked";
}
This works most of the time (so far), but many publishers such as yahoo use slight variations of the "self !== top" code which makes preg_match not work. I am wondering if there is any universal/general test that I can implement to know whether or not a given URL will block an iframe or not.
thanks