admin管理员组文章数量:1321825
Need to clear local storage on browser tab closed not on refresh. I tried
window.onbeforeunload = function (e) {
localStorage.clear();
};
it clears the localstorage when browser refresh happens. I want to force the user to login when the user close browser tab.
Need to clear local storage on browser tab closed not on refresh. I tried
window.onbeforeunload = function (e) {
localStorage.clear();
};
it clears the localstorage when browser refresh happens. I want to force the user to login when the user close browser tab.
Share Improve this question edited Oct 16, 2017 at 12:12 phuzi 13.1k4 gold badges29 silver badges59 bronze badges asked Oct 16, 2017 at 12:09 SankarSankar 3592 gold badges6 silver badges20 bronze badges 4- 1 Possible duplicate of stackoverflow./questions/9943220/… – Karan Singh Dhir Commented Oct 16, 2017 at 12:39
-
Try this
localStorage.$reset();
– Ramesh Rajendran Commented Oct 16, 2017 at 12:45 - 1 Possible duplicate of How to delete a localStorage item when the browser window/tab is closed? – Ramesh Rajendran Commented Oct 16, 2017 at 12:45
- stackoverflow./questions/39128931/… – Shub Commented Mar 29, 2024 at 14:30
2 Answers
Reset to default 4Refreshing and closing a tab/window is the same event as far as the browsers are concerned.
Best would be to use session storage
rather than local storage
as session would be active until the tab/window is closed and not refreshed and you aren't saving persistent data.
Have a look here
Use this code.
window.onload = window.localStorage.clear();
本文标签: javascriptNeed to clear local storage on browser tab closed not on refreshStack Overflow
版权声明:本文标题:javascript - Need to clear local storage on browser tab closed not on refresh - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742104108a2420940.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论