js判断浏览器的关闭标签动作和刷新的事件

来源:互联网 发布:电视盒子软件2017 编辑:程序博客网 时间:2024/06/05 10:12
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><script src="https://unpkg.com/vue"></script></head><body><div id="vue01"><input placeholder="请输入" ><h1>测试关闭浏览器</h1></div><script>  //关闭浏览器提示信息window.onbeforeunload = function (e) {  e = e || window.event;  var y = e.clientY;  if (y <= 0 || y >= Math.max(document.body ? document.body.clientHeight : 0, document.documentElement ? document.documentElement.clientHeight : 0))  {    //IE 和 Firefox     alert("IE or Firefox");    e.returnValue = "确定要刷新或关闭浏览器窗口?";  }  //谷歌  console.log("beforeclosing");  return "确定要刷新或关闭浏览器窗口?"; }</script></body></html>

原创粉丝点击