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

浪子不回头ぞ 提交于 2019-12-25 08:47:10

问题


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.


回答1:


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
    };


来源:https://stackoverflow.com/questions/40245416/how-to-make-a-jquery-count-down-timer-that-doesnt-restart-on-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!