[英]How to detect Close Tab/ Browser for logout in javascript vue.js with quasar framework
我想在關閉選項卡上調用注銷 function 或僅關閉瀏覽器,而不是在刷新頁面上。
我嘗試使用下面的示例代碼,它完美地在關閉選項卡上注銷,但如果我刷新頁面,它也會注銷。
我想防止在刷新頁面上注銷。
window.addEventListener('beforeunload', this.logout)
我在mounted() function 中添加了以下代碼,它適用於我
window.addEventListener("beforeunload", (event) => {
// on the navigation type checking refresh or close tab/browser for logout
console.log("performance.navigation.type " + performance.navigation.type);
if (performance.navigation.type != 1) {
this.logout();
}
return false;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.