js设置当前窗口为最上层窗口

实际使用iframe框架时会遇到当前窗口页面不能位于最上层窗口的情况,或者是防止自己的网站被别人放在他们的iframe中,这时就需要设置:

  <script language="javascript" type="text/javascript">
        if (window.top != null && window.top.location != window.location) {
            window.top.location = window.location;
        }或者
      if (window.top.location.href!=location.href) {
          window.top.location.href=location.href;
      }
    </script>
原文地址:https://www.cnblogs.com/moumou0213/p/6518895.html