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
})
},