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如果有人测试可以评论一下哦。 ↩︎
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/83929.html