Take a look at sessionStorage, which works similarly to localStorage, but does not save any data after closing a tab / window / browser.
It will also be more secure than localStorage, since no data will be stored after the session ends. For more information on security, see the W3 Storage Specification .
However, if you store sensitive data, I would recommend cookies as data in sessionStorage, and localStorage can be viewed and edited by the user and potentially open to XSS attacks.
source share