其他分享
首页 > 其他分享> > js、关闭或刷新浏览器弹出弹窗

js、关闭或刷新浏览器弹出弹窗

作者:互联网

js、关闭或刷新浏览器弹出弹窗

H5

<html>
    <head>
        <style>
        </style>
    </head>
    <body>
        <script lang="typescript/js">
            //初始化关闭
            window.addEventListener("beforeunload", function(e) {
                    var confirmationMessage = "你确定要离开吗?";
                    (e || window.event).returnValue = confirmationMessage; // 兼容 Gecko + IE
                    return confirmationMessage; // 兼容 Gecko + Webkit, Safari, Chrome
            });
        </script>
    </body>
</html>

VUE

  mounted () {
    // 初始化关闭
    window.addEventListener('beforeunload', function (e) {
        let confirmationMessage = '您确定要关闭窗口吗?';
        (e || window.event).returnValue = confirmationMessage
        return confirmationMessage
    })
  },

标签:浏览器,returnValue,confirmationMessage,js,window,关闭,beforeunload,event,弹窗
来源: https://blog.csdn.net/qingdi1/article/details/121361382