I am implementing some custom timer which is purpose to count specified time. That timer needs to store counted time if user manually reload page. This parts works. But after specified time (in this case 5 seconds) user needs to be redirected.
For that purpose I using sessionStorage to keep current counted time. But after 5 second I am trying to remove item from sessionStorage and it doesn't work!
Where I a made mistake? How I can remove item from sessionStorage in my case? Thanks
var currentTime = sessionStorage.getItem("currentTime");
if (currentTime == null) {
currentTime = 0;
}
setInterval(function () {
currentTime++;
if (currentTime == 5) {
sessionStorage.removeItem("currentTime");
location.reload();
}
sessionStorage.setItem('currentTime', currentTime);
}, 1000);