Help, please, implement a one-time page reload. The user enters the site, the page reloads once and does not reload again until the next session.

The code turned out like this, but does not work. Please help me figure it out. It seems to me that I messed up with the keys in sessionStorage.

var reload = 0; if(sessionStorage.getItem(reload==0)){ window.location.reload(); reload=1; } 

    1 answer 1

    You are not only confused with the keys, but in general with the solution algorithm. You need to try to get the reload key value from the current session ( sessionStorage ). If the value is, then do nothing. If not, write the value to the session, and refresh the page.

    The code for this should be as follows.

     var reload = sessionStorage.getItem('reload'); if(!reload){ sessionStorage.setItem('reload', 1); window.location.reload(); }