Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Created April 23, 2012 12:08
Show Gist options
  • Save johnathan-sewell/2470535 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/2470535 to your computer and use it in GitHub Desktop.
JavaScript iframe breakout
var isFrame;
try {
if (top.location.href !== window.location.href) {
isFrame = true;
}
} catch (e) {
// if you're in an iframe in a different domain, the top.location check
// results in a security exception
isFrame = true;
}
if (isFrame){
//if (window.name !== "CMS_Frame") //don't break out of this one
window.parent.location.href = window.location.href;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment