js检测关闭页面或浏览器

来源:互联网 发布:twisted python 安装 编辑:程序博客网 时间:2024/06/08 18:58

使用onunload 或 onbeforeunload 事件监听

window.addEventListener("beforeunload", function (e) {  var confirmationMessage = "\o/";  (e || window.event).returnValue = confirmationMessage; //Gecko + IE  return confirmationMessage;                            //Webkit, Safari, Chrome});

这样也行:

window.onbeforeunload = function () {    return "Do you really want to close?";};

参考链接

0 0
原创粉丝点击