Skip to content
Advertisement

I’m trying to change the localstorage expiration time from forever to 24 hours

I have implemented a dialogue which shows whenever a user access the website. However, I want the dialogue to reappear after 24 hours if someone accesses the site clicking on the cookie. Unfortunately, I spent a lot of time researching and I haven’t found any solution which applies to my scenario. Below is the code I’m trying to modify,

JavaScript

Advertisement

Answer

localStorage has no expiration time, but you can compare timestamps:

JavaScript
Advertisement