I have a div that I want to display (then will collapse after a timeout) when one first visits my site, but after that I want that div to remain collapsed.
I found this jsfiddle that seems perfect for me:
https://jsfiddle.net/hibbard_eu/mjgdrg1f/
var hasSeenGreeting = localStorage.getItem("greeting");
I implemented it on my site, but after two hours I still can’t get the local storage variable to save! I created a test page that has ONLY the sample and it works just fine:
https://importarchive.com/test.php
But on my main site I just can’t get the variable to save into local storage. I have even put the “var hasSeenGreeting = localStorage.getItem(“greeting”);” as the first script in the head, but it’s not working.
Thanks in advance to anyone that can help!
(I know my site is a mess — it’s a side project that evolved over decades)
I expect the local storage key ‘greeting’ to be set as true as soon as the page loads. Instead, no variable is being saved at all.
Darren is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2