当前位置: 代码迷 >> Web前端 >> 封闭浏览器触发事件
  详细解决方案

封闭浏览器触发事件

热度:84   发布时间:2012-10-12 10:17:04.0
关闭浏览器触发事件

function f() {

??? if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altkey) {

??????? alert("1");

??? }

}

window.onbeforeunload = f;

补充说明:window.onbeforeunload 是窗口关闭触发 f函数,但同时也会在页面 刷新时触发 ,所以在函数f中还要补充条件,计算鼠标是否在窗体内(当用户关闭页面 时,鼠标是移动到上角的X处)

  相关解决方案