Delete value from sessionStorage JavaScript -
I am implementing some custom timers that aim to calculate the specified time. The timer needs to be counted when the user loads manually. This section works but after the specified time (5 seconds in this case) the user needs to be redirected.
For that purpose I am using session storage to keep current calculation time. But after 5 seconds I am trying to get rid of the session and it does not work!
Where did I make a mistake? How can I remove items from sessionStorage in my case? Thanks
var current time = sessionStorage.getItem ("current time"); If (current time == zero) {currentTime = 0; } SetInterval (function {currentTime ++; if (currentTime == 5) {sessionStorage.removeItem ("currentTime"); location.reload ();} sessionStorage.setItem ('currentTime', current time);), 1000) ;
The problem is that location.reload ()
doesn Javascript can not end execution Therefore, after that line, sessionStorage.setItem ('current time, current time);
is still going on. To fix this problem, that line should be if (current time == 5)
.
Comments
Post a Comment