I have an application which stores the user data in browser's localStorage. So, user can get those data even across browser tabs and windows. But what I want to do is to clear localStorage when user closes the browser window.
I used beforeunload function to achieve this but it triggers on tab close also.
So, please help me if there is any way to detect whether browser tab is closed or browser window.
PS: I can't use sessionStorage as it destroys on browser tab close.