//浏览器关闭或刷新事件 function bindCloseBrowser() { var a = "注意!!\n您即将离开页面!离开后可能会导致数据丢失\n\n您确定要离开吗?"; window.onbeforeunload = function (b) { b = b || window.event; b.returnValue = a; return a } }
监听页面关闭: window.onbeforeunload = function() { //鼠标相对于用户屏幕的水平位置 - 窗口左上角相对于屏幕左上角的水平位置 = 鼠标在当前窗口上的水平位置 var n = window.event.screenX - window.screenLeft; //鼠标在当前窗口内时,n<m,b为false:鼠标在当前窗口外时,n>m,b为true.20这个值是指关闭按钮的宽度 var b = n > document.documentElement.
/** * 监听浏览器标签页的显示与隐藏 */ class ListenerPageVisibility { constructor () { // 设置隐藏属性和改变可见属性的事件的名称 this.hidden = '' this.visibilityChange = '' if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support this.hidden