js关闭当前窗口、标签页

js关闭当前窗口、标签页

1、通过a标签

<a href="javascript:window.opener=null;window.open('','_self');window.close();">关闭当前窗口</a>

2、通过按钮

<body>
    <button id="btn">关闭当前窗口</button>
</body>

<script>
    document.getElementById('btn').onclick = function() {
        window.opener = null
        window.close()
    }
</script>

猜你喜欢

转载自blog.csdn.net/weixin_42497122/article/details/105318701
今日推荐