OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

SetTimeout pauses on alert

  • Thread starter Thread starter user1181942
  • Start date Start date
U

user1181942

Guest
I have to display a timer on my webpage. I am doing this using Javascript SetTimeout method. My code is like:

Code:
function UpdateTimer() {
        var hfTimer = $('#<%= hfTimer.ClientID %>');
        $('#spnTimer').html(GetElapsedTime(hfTimer.val()));
        hfTimer.val(parseInt(hfTimer.val(), 10) + 1);
        setTimeout(UpdateTimer, 1000);
    }

    function GetElapsedTime(seconds) {
        var sec_num = parseInt(seconds, 10);
        var hours = Math.floor(sec_num / 3600);
        var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
        var seconds = sec_num - (hours * 3600) - (minutes * 60);

        if (hours < 10) { hours = "0" + hours; }
        if (minutes < 10) { minutes = "0" + minutes; }
        if (seconds < 10) { seconds = "0" + seconds; }
        var time = hours + ':' + minutes + ':' + seconds;
        return time;
    }

Timer works fine until there is some alert pops out. Alert could be a simple jquery alert or sometime validation summary alert. When this alert comes timer pauses and as I click on "Ok", timer starts running again. I don't want this pause to happen. Is there any solution to this. Please help me.

<p>I have to display a timer on my webpage. I am doing this using Javascript SetTimeout method.
My code is like:</p>

<pre><code>function UpdateTimer() {
var hfTimer = $('#<%= hfTimer.ClientID %>');
$('#spnTimer').html(GetElapsedTime(hfTimer.val()));
hfTimer.val(parseInt(hfTimer.val(), 10) + 1);
setTimeout(UpdateTimer, 1000);
}

function GetElapsedTime(seconds) {
var sec_num = parseInt(seconds, 10);
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);

if (hours < 10) { hours = "0" + hours; }
if (minutes < 10) { minutes = "0" + minutes; }
if (seconds < 10) { seconds = "0" + seconds; }
var time = hours + ':' + minutes + ':' + seconds;
return time;
}
</code></pre>

<p>Timer works fine until there is some alert pops out. Alert could be a simple jquery alert or sometime validation summary alert. When this alert comes timer pauses and as I click on "Ok", timer starts running again.
I don't want this pause to happen.
Is there any solution to this. Please help me.</p>
 

Latest posts

Top