I'm trying to store some data through localStorage so I can load it again in the same page of a web if this page is refreshed.
Imagine a user writing a comment, he refreshes the page and I want to load again the comment through localStorage so the user can keep editing his comment after that refresh.
The issue I'm facing is that, what if the user has multiple tabs open on the same page, writing different comments? How could I retrieve the correct information for one specific tab?
SessionStorage is exactly what you need. It behaves the same way as
localStorage, but is dedicated to the page session. The downside ofsessionStorageis that if the user will close the tab, he'll loose it.So, depending on your use case you can use:
See: