Archived topic
Load animation only once per website visit
5 replies · Started by Dominik on November 12, 2020
Hi there,
we have made a small intro animation with javascript and css and need to show the animation only once per website visit. We couldn´t find out how this could be made.
https://ccl.brandwerk-digital.com/
Thanks for your help!
Dominik
Hi there,
aside of using Cookies to detect a users first visit you can use localStorage to store a variable for the visited status and then use that as a condition to run your code. Heres an example of that.
Hi David,
thanks for the input. I couldn´t get it run and tried the function with an alert. that works well – but only one time. Is it possible to create a function that runs the code once per website visit..if you click the start page a second, third,...time, no code will run. But if you close the window and open a new one...the code will run once again?
Thanks!
Probably want to swap localStorage for sessionStorage see here:
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
sessionStorage differs in that the variable is only stored for the current tab whilst it is open. Once closed sessionStorage gets cleaned.
Perfect – Thank you very much!!!
You're welcome