I want to add in case someone will have the same issue as me. (im a beginner in js btw).
I was following this thread and trying the below but the if was firing when entering the page (on first load).
sessionStorage.setItem('test',false);
if (sessionStorage.getItem('test') != "false") {
..........
}
What did it for me was changing != to ==. So in my case it looks like this:
//other function that sets session and reloads
sessionStorage.setItem('reload', 'false');
location.reload();
//then the if after reload
if ( sessionStorage.getItem('reload') == 'false' ) {
//whatever you want here
//setting it true again so it doesn't fire when I manually reload.
sessionStorage.setItem('reload', 'true');
}
I find it a bit counterintuitive because you'd think to set the session to true and then fire the if if session != false... but hey it works, doesn't fire on first page load and then fires when i execute the page reload.