How to keep Timer running in background using script in mvc

Viewed 89
<script>
var timelimit=20;
var taskid=12
        function StartTimer(timelimit, taskid) {
            debugger;

            if (currentTime <= 0) {
                resetTimer();
                StartTimer(timelimit, taskid);
            } else {
                myTimer = setInterval(timerTick, myTimerSpeed);

            }

            // $('.divstoptimer').show();
            $('#timerCheck_' + taskid).hide();
            $('#closetimer_' + taskid).show();
            $('#countdown_' + taskid).show();

            //$('.countdown').show();
        }

        function stopTimer(timelimit, taskid) {

            clearInterval(myTimer);
            $('#timerCheck_' + taskid).show();
            $('#closetimer_' + taskid).hide();
            $('#countdown_' + taskid).show();
        }

        function timerTick() {

            currentTime--

            var hours = currentTime / 3600;
            var minutes = parseInt((currentTime % 3600) / 60);
            var seconds = (currentTime % 3600) % 60;

            var finalDisplaytimer = minutes + " mins " + seconds + " sec ";

            $('.countdown').html(finalDisplaytimer);

            if (currentTime == 0) {
                stopTimer();

            }
        }
        window.onload = function () {

        };


    </script>

Above is my script for Timer but when I am reloading page or goes out of the page then my timer stops runnimg which I do not want.I want my timer to keep running in background. Please help me in how to achieve this.

0 Answers
Related