zoukankan      html  css  js  c++  java
  • chrome JS关闭当前页无效问题

    如果没有父窗口,JS中 

    window.opener = null;

    window.open("", "_self");

    window.close(); 

    对chrome 及Firefox是无效的,那么针对这种情况该怎么办呢。

    工具/原料

    • chrome,Firefox浏览器

    方法/步骤

    1. 1

      JS 关闭网页,之前通过以上方式,可以解决Firefox chrome等浏览器不兼容的问题,但是随着浏览器版本升级,现在无效了。会提示:

      Scripts may close only the windows that were opened by it.

    2. 2

      那么如下写法可以解决该问题: 即,如果是以下浏览器,则设置当前页为空白页。

      $("#closeBtn").click(function(){

      var userAgent = navigator.userAgent;

      if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {

         window.location.href="about:blank";

      } else {

         window.opener = null;

         window.open("", "_self");

         window.close();

      }});

      });

  • 相关阅读:
    Go:获取命令行参数
    Go:文件操作
    Go:类型断言
    GO:interface
    Go:面向"对象"
    Go:工厂模式
    layui中流加载layui.flow
    js显示当前时间
    layui中的分页laypage
    layui中的多图上传
  • 原文地址:https://www.cnblogs.com/wdlhao/p/5329730.html
Copyright © 2011-2022 走看看