Good day. Tell me, please, how to make a one-time reload of the page. I did this:

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

But the page still does not reload. What am I doing wrong?

    1 answer 1

    What

    Single page reload

    ?

    The current algorithm reloads the page exactly once. When you first visit the current browser session. Then you set the reload parameter and the page stops running. You need to determine at what point the page needs to be restarted again and then reset the reload parameter.

    This code will reload the page every odd visit.

     $(document).ready(function() { var reload = sessionStorage.getItem('reload'); if(!reload){ sessionStorage.setItem('reload', 1); window.location.reload(); } else sessionStorage.setItem('reload', null); }); 
    • "only once. On first visit" - from the current browser session. - Igor
    • Single reboot - I mean that once during the current session. In case a person has cleared the history, a one-time reset will occur again. That is, for some reason, my algorithm does not reload the page, if the history is cleared. - Kira
    • @Kira Clearing history implies clearing sessions? It seems to me that no. Sessions are cleared when the browser is restarted. Maybe you need to use localStorage ? - Anton Shchyrov
    • @Kira uh, why did you decide that clearing the history without closing the browser starts a new session? - Igor
    • one
      @Igor Thanks for the clarification. Corrected the answer - Anton Shchyrov