前端——js关闭页面方法

吃可爱长大的小学妹 提交于 2019-12-07 19:49:46

js关闭当前页面,当该页面不是其他页面打开的,而是直接输入url,

直接用window.close()无法关闭。

以下代码可以实现不同浏览器的关闭操作:

function CloseWebPage(){ if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") !=-1) {
window.location.href="about:blank";
window.close();
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
}

function CloseWebPage(){ if (navigator.userAgent.indexOf("MSIE") > 0) { if (navigator.userAgent.indexOf("MSIE 6.0") > 0) { window.opener = null; window.close(); } else { window.open('', '_top'); window.top.close(); } } else if (navigator.userAgent.indexOf("Firefox") > 0) { window.location.href = 'about:blank '; } else { window.opener = null; window.open('', '_self', ''); window.close(); } }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!