js捕捉浏览器关闭事件


window.onbeforeunload = function (e) {
	e = e || window.event;
	var y = window.event.clientY;//e.clientY:只有IE8支持
	if (y <= 0//点击浏览器或者选项卡的关闭按钮
	    || y >= Math.max(document.body ? document.body.clientHeight : 0, 
            document.documentElement ?document.documentElement.clientHeight : 0)//点击任务栏的关闭按钮
	   ) {
		//浏览器关闭之前执行的操作
		$.ajax({
		    type: "POST",
    		    url: "<%=path%>/pages/common/logoutForWebClose.action",
		    dataType: "text",
		    async: false,
		    success: function(data){
			alert("closeSuccess");
		    }
		});
	}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM