Home » Jquery » javascript – Remember the time left when browser refresh using jquery

javascript – Remember the time left when browser refresh using jquery

Posted by: admin February 22, 2020 Leave a comment

Questions:

This code below pops up with an interval of 5 seconds, 10 seconds & 15 seconds and inside this box is a contact form 7 form

So when I refresh the page it goes back to 5 seconds all the time.

var iteration = 0;
var times = [5,10,15]
var showPopUp = function(time) {
    setTimeout(function() { 
        jQuery('.pop_timer_box').css('display','flex');
        Cookies.set('popup_box', time); 
    }, time)

}

showPopUp(times[iteration]);

jQuery('body').on('click', '.cclose_pop', function() {
    jQuery('.pop_timer_box').hide();
    iteration +=1;
    if (iteration < 3) {
      showPopUp(times[iteration])
    }
});

How can I make it so that when I refresh the page will will remember what it has left

and also make it all stop when contact form 7 is successfully submitted (popup will not show anymore maybe until browser exit)

Thank in advance for the help

How to&Answer:

You should take a look at the localstorage function.

You can set / update Information like this:

localStorage.setItem("seconds", time);

After the page has been loaded simply use

localStorage.getItem("seconds");

Answer:

Nice try! but your code still have problems, i think var times is not realiza