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
    })
  },
上一篇:事件对象 ------------- 阻止默认行为的方法


下一篇:食蔬宝收银称重软件V1.0