Skip to content

Instantly share code, notes, and snippets.

@freejoe76
Created October 13, 2014 20:25
Show Gist options
  • Save freejoe76/e6e2d3cf37288a00498a to your computer and use it in GitHub Desktop.
Save freejoe76/e6e2d3cf37288a00498a to your computer and use it in GitHub Desktop.
iframe_breaker.js
if (top !== self)
{
// We want to track when this happens, which we do with a custom
// ?source=framebuster query added to the URL.
// The challenge is, often there's already a ?source=rss on the URL,
// which means we have to handle that too.
var sourcedomain = 'denverpost.com';
var sourceurl = self.document.location.toString();
var referrer = document.referrer.split('/')[2];
if ( sourceurl.indexOf("www." + sourcedomain) > 0 && referrer.indexOf(sourcedomain) < 0 )
{
if ( referrer.indexOf("google") < 0 && referrer.indexOf("facebook") < 0 && referrer.indexOf("images.") < 0 && referrer.indexOf("ow.ly") < 0 && referrer.indexOf("reddit") < 0 && referrer.indexOf("stumbleupon") < 0 )
{
top.location.replace(self.location);
var sourcetag = "skipframe-" + referrer;
if ( sourceurl.indexOf("?source") > 0 || sourceurl.indexOf("&source") > 0 )
{
top.location.replace(sourceurl + sourcetag);
}
else if ( sourceurl.indexOf("?") == -1 )
{
top.location.replace(sourceurl + "?source=" + sourcetag);
}
else
{
top.location.replace(sourceurl + sourcetag);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment