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