window.onbeforeunload = function (e) {
e = e || window.event;
var timer = setInterval(function(){
fun1();
clearInterval(timer);
}, 1000); //在点击取消关闭页面按钮时启动计时器,执行一次就暂停
if (e) {
e.returnValue = '关闭提示';
}
return '关闭提示';
};
window.addEventListener("beforeunload", function (event) {
event.returnValue = "关闭提示";
});
function fun1() {
console.log(1);
}
JS在点击取消关闭页面提示(onbeforeunload)后调用函数
于 2021-12-12 05:07:40 首次发布