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");
		    }
		});
	}
}
posted @ 2016-11-11 16:10  南村一哥  阅读(5923)  评论(0编辑  收藏  举报