How can you save / cache bool variable for the duration of the session with the ability to reload the page, but when you close the tab to reset, something like this

 localStorage.setItem('rebuild', 'true'); var bool = localStorage.getItem('rebuild'); window.onscroll = function(){ var scrollT = window.pageYOffset; if(scroll > 300 && bool === true){ init("canvas"); bool = false; } } 

and then replace the above for the session?

  • bool === true - this condition will always be false because only lines are stored in localStorage - Grundy
  • @Grundy but the sessionStorage disappears after a reboot, but I need it so that it is reset to zero after the page closes, I thought through cookies, but somehow it’s probably not right - Lieutenant Jim Dangle
  • No, it does not disappear after a reboot - Grundy
  • one
    The title should describe the essence of the question, not a request for help) - Nick Volynkin

1 answer 1

decided in this way

 function getParam (){ if(sessionStorage.getItem('rebuild') == '0'){ tempVar = sessionStorage.getItem('rebuild'); init('canvas'); } else { sessionStorage.setItem('rebuild', '1'); tempVar = sessionStorage.getItem('rebuild'); } } getParam(); window.onscroll = function(){ var scrollT = window.pageYOffset; if(scroll > 300 && tempVar == '1'){ init('canvas'); tempVar = '0'; } } if(tempVar === '0'){ sessionStorage.setItem('rebuild', '0'); } 

Thanks @Grundy, for the help :)

If somewhere is not right, I will be grateful for the advice!