需求:在頁面關(guān)閉的時候監(jiān)聽事件,但是刷新的時候并不執(zhí)行。
實現(xiàn):
window.onbeforeunload = function(){
? ? ? var? n? =? window.event.screenX? -? window.screenLeft;?
? ? ? var? b? =? n? >? document.documentElement.scrollWidth-20;?
? ? ? if(b? &&? window.event.clientY? <? 0? ||? window.event.altKey)?
? ? ? {? //頁面關(guān)閉
? ? ? }else{
? ? ? ? ? // 頁面刷新 ??
? ? }?
}