I don't understand how sessionStorage works. I want to have an event happen on only the initial page load.
I'm (trying) to do this by checking if the session is new. The idea is below:
$(function() {
sessionStorage.setItem('isNewSession', 'true');
if (sessionStorage.getItem("isNewSession")) {
// do stuff on the first page load
} else {
// don't do it after
}
});
So when the page first loads, it looks like the sessionStorage
is set to true
. After that, during the duration of the users visit to the page, what I want to happen only once always happens, because I can see sessionStorage
is always true
.
If I set it to false
if sessionStorage returns true
then obviously what I want to happen just won't happen.
I investigated a session cookie but this again persists throughout the users visit, and not just the first load.
How do I handle this? How can I have an event fire only on initial page load, and not throughout the remaining users visit?
FOR CONTEXT: The "event" is an animation in the navigation bar.