[英]How to detect Close Tab/ Browser for logout in javascript vue.js with quasar framework
I want to call the logout function on the close tab or close the browser only, not on the refresh page.我想在关闭选项卡上调用注销 function 或仅关闭浏览器,而不是在刷新页面上。
I tried with the below example code it doing logout on the close tab perfectly but also doing logout if I refresh the page.我尝试使用下面的示例代码,它完美地在关闭选项卡上注销,但如果我刷新页面,它也会注销。
I want to prevent logout on the refresh page.我想防止在刷新页面上注销。
window.addEventListener('beforeunload', this.logout)
I added the below code in mounted() function and it works for me我在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.