likes
comments
collection
share

Vue关闭当前浏览器窗口

作者站长头像
站长
· 阅读数 282
  1. 传统的JS关闭当前窗口
window.opener=null;
window.open('',self);
window.close();
  1. vue关闭当前窗口
window.opener = null
window.open("about:blank", "_top").close()
  1. 其他
var userAgent = navigator.userAgent;
if (userAgent.indexOf("MSIE") > 0) {
    if (userAgent.indexOf("MSIE 6.0") > 0) {
      window.opener = null;
      window.close();
    } else {
      window.open("", "_top");
      window.top.close();
    }
} else if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
    window.location.href = "about:blank "; //火狐默认状态非window.open的页面window.close是无效的
    //window.history.go(-2);
} else {
    window.opener = null;
    window.open("about:blank", "_self");
    window.close();
}

4.说明

_blank - URL加载到一个新的窗口(默认)
_parent - URL加载到父框架
_self - URL替换当前页面
_top - URL替换任何可加载的框架集