Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created November 25, 2014 04:01
Show Gist options
  • Save kiinlam/5b52b40bbc6c99eda37b to your computer and use it in GitHub Desktop.
Save kiinlam/5b52b40bbc6c99eda37b to your computer and use it in GitHub Desktop.
防止网页被嵌入框架的代码
/*
* 作者: 阮一峰 http://www.ruanyifeng.com/
* http://www.ruanyifeng.com/blog/2010/08/anti-frameset_javascript_codes_continued.html
*/
try{
  top.location.hostname;
  if (top.location.hostname != window.location.hostname) {
    top.location.href =window.location.href;
  }
}
catch(e){
  top.location.href = window.location.href;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment