Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear sessionStorage when navigating to another page but not on refresh?

I have some check boxes in one of my webpages, and this page has to refresh every 1 minute for some data consistency issues.

I am using window.sessionStoage to persist the check boxes that have been checked so that the user doesn't lose the boxes already checked on page refresh.

But I want to clear the sessionStorage when the user navigates away from that page (not necessarily leaving my website, might be going to another page on the same website), and for the same if I use the onunload event then the storage will be cleared in case of refresh also.

Is there any other event or any workaround that could help me achieve this.

like image 453
Shubham Batra Avatar asked Nov 09 '22 04:11

Shubham Batra


1 Answers

May you try to save the path/name of the current page in you session-storage and on each init of your page check if the pagename equals the name in the sessionstorage. If not, you can clear it.

like image 154
Andy Avatar answered Nov 14 '22 21:11

Andy