0

I have a basic form asking to join an email list that I make disappear when someone submits and not reappear by hiding an id in localStorage. I also have a button you can press to make the div disappear should user not want to sign up for email, also done in localStorage. Both of these click events trigger 'hideEmail()'

Is it possible to reverse hiding the id by checking when it was placed in localStorage and if it was over x amount of time change it back?

function hideEmail() {
    $('#footer').hide();
    localStorage.setItem('hidden', 'true'); //store state in localStorage
}

$(document).ready(function(){
    var hidden = localStorage.getItem('hidden');
    if(hidden === 'true'){
        $('#footer').hide();
    }
});
gpb14
  • 3
  • 7

1 Answers1

0

Are you referring to, say, when the user closes the page, and when the user reopens the page, check if the user has passed the time allowance so that the footer would be unhidden?

If so, want you want to be using are cookies. You define them as such:

var d = new Date();
var username = "any_username";
// Set cookie to expire in, say, 4 days. Then you can do an if statement and check if cookie is expired, so you can set hidden to false.
document.cookie = "username=" + username + ";expires=" + d.getDate()+4+";";
  • I'm trying to avoid cookies, adding a timestamp to local storage event solves my problem tho, thanks – gpb14 Jun 04 '18 at 04:13