简体   繁体   中英

Start timer every 1 minute Jquery

Trying to start my timer if the app is in idle start for 1 minute. My timer is starting initially, how do I check whether my app is idle or not. And also if the timer starts and interrupts in between then the timer should disappear and stay on the same page. else redirect to home page.

JS:

var interval = setInterval(function() {
    var timer = $('span').html();
    var seconds = parseInt(timer,10);
    seconds -= 1;

    if (seconds < 0 ) {
        seconds = 59;
    }
    else if (seconds < 10 && length.seconds != 2) seconds = '0' + seconds;
    $('span').html(seconds);

    if (seconds == 0)
        clearInterval(interval);
}, 1000);

This is what I have tried:

Demo

         $(document).ready(function(){
            var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
                idleTime = 0;
                //Zero the idle timer on mouse movement.
                $(this).mousemove(function (e) {
                    idleTime = 0;
                });
                $(this).keypress(function (e) {
                    idleTime = 0;
                });

                });

                //after every one minute this function will call and it check idleTime is    
                //increment if it is one then reload the page               
                function timerIncrement() {
                idleTime = idleTime + 1;
                if (idleTime > 1) { // 1 minutes
                    //alert();
                    window.location.reload();
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM