0

I am having a Javascript function which displays timer. Now,when timer reaches 2 minutes, I want to display a alert and continue my timer function. But,my timer function stops till user clicks 'Ok' and then resumes from 1:59 secs.

Can anyone tell me how to keep the timer function running while popup box is displayed?

Here's my function to display timer.

var minutes=5;
var seconds=59;

function time_display(){
  if(minutes==2 && seconds==0){
    setTimeout('display_time_alert_two_minutes_left()',100);
  }
  if (seconds<=0){
    seconds=59;
    if(minutes>0)
      minutes-=1;
  }
  else
    seconds-=1;
  $('time_left_in_minutes').innerHTML = minutes+"."+ ljust_zero(seconds);
  setTimeout("time_display()",1000);
}
time_display();

and this is my alert function.

function display_time_alert_two_minutes_left(){
    alert('Two minutes left');
}

3 Answers 3

3

Alert is a blocker, use custom javascript popups like lightbox,lytebox,jquery dialog,fancybox etc.

Or you can simply show/hide a floating div. This will solve the problem of your timer getting stuck, and also enhance your user experience.

0

How about you use something thats no so intrusive, something like this

0

As alert() stops the rest of the javascript code executing, it would be better to use something that doesn't require an imperitive style of incrementing time.

How about you actually use the time/date functionality, which will 'keep counting'?

Edit : This will stop the web page updating when you call alert() but it will keep counting fine whilst an alert is open.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.