[英]How to capture browser window clsoing event?
嗨,我想捕獲Windows關閉事件,並希望刪除會話值。 經過幾次搜索后,我發現了onBeforeUnload事件,每次您導航到不同頁面或卸載頁面時都會觸發該事件。即使在重新加載時也會觸發此事件,這不是我的要求。 我希望所有瀏覽器中僅特定於Windows關閉事件才能使會話值無效。
/* The most acceptable answer seemed to be as follows in vanilla JS
and was addressed at the linked address already.*/
window.onbeforeunload = closingCode;
function closingCode(){
//I would capture the URL prior to unload here and if it does NOT
//exist or is not your url domain then you can unload variables here
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.