Skip to content

Instantly share code, notes, and snippets.

@NuarHaruha
Created November 12, 2011 07:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NuarHaruha/1360205 to your computer and use it in GitHub Desktop.
Save NuarHaruha/1360205 to your computer and use it in GitHub Desktop.
Safely break out of an iframe for blogspot/blogger
/***
Safely break out of an iframe for blogspot.com
@author Nuar H. Noah
*/
var myblog = { hostname: top.location.hostname, whitelist: Array() }
myblog.breakfree = function(){
if (top.location != self.location) {
var curDomain = this.hostname.split('.')[1];
this.whitelist['blogspot'] = 1;
this.whitelist['blogger'] = 1; // Blogspot template design preview
this.whitelist['google'] = 1; // Google serviceses - translate cached
if ( ! this.whitelist[curDomain] ) {
top.location = self.location.href;
}
}
}
myblog.breakfree();
delete window.myblog; // gc
@NuarHaruha
Copy link
Author

xml safe escape..
if u want to post directly to blogspot template you'll need to replace the single quote' character with '

---- this.whitelist['blogspot'] = 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment