JS关闭当前窗口网页
功能具体描述:
点击页面弹出对话框,点击确定,即可关闭页面。(兼容EDGE,火狐,谷歌浏览器)1
实现效果
实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="button" value='退出/关闭页面' class="exit">
<script>
document.querySelector(".exit").addEventListener('click', function () {
if (confirm('确定要退出吗?')) {
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();
};
}
})
</script>
</body>
</html>
PS:ie6/7/8如果有人测试可以评论一下哦。 ↩︎