Skip to content

Delete a localStorage item when the browser window/tab is closed

We can use the window.beforeunload event to find out if a tab is closed and then we can clear the local storage. beforeunload event gets triggered when a window or browser tab is about to close.

window.onbeforeunload = () => {
See also  Forming a Magic Square - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.