saifudeen ni
saifudeen ni

Reputation: 145

How to make a jquery count-down timer that doesn't restart on refresh

I am creating a web template for sale, but I can't make timer count down, I don't how to make it. I need timer count down (when a date is added, it should be decreased), also it should not restart on refresh time or shut down time. Please help me to do this code... I will use it in my template.

Upvotes: 0

Views: 100

Answers (1)

Korgrue
Korgrue

Reputation: 3478

If you are not working with a database, then you can use HTML5 localstorage. Store a variable on the users local machine if they have already visited. When the page loads, do a check of local storage for that variable. If it is not null, then don't init the timer as they have already been on the site.

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Create localstoreage var:

var myStorage = localStorage;

If user loads page - store true in "visited"

localStorage.setItem('visited', 'true');

If visitor reloads page, check for visited == true, and if true, dont trigger timer.

var hasVisited = function() {
    var didVisit = myStorage.getItem('visited');
        if(didVisit == "true"){
         //do nothing}
    }else{
         //start your timer
    };

Upvotes: 1

Related Questions