Reputation: 2563
With the following code I want to count down and after the timer has reached 00:00 it will change window location. All is working up until that point. My question is how do I make this process repeat again after the window location has changed? I will be using this for a chrome extension to run in the background.
var sec = 5; // set the seconds
var min = 10; // set the minutes
function countDown() {
sec--;
if (sec == -1) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec <= 9) {
sec = "0" + sec;
}
time = (min <= 9 ? "0" + min : min) + " min and " + sec + " sec ";
document.getElementById('theTime').innerHTML = time;
SD = window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') {
sec = "00";
window.clearTimeout(SD);
window.location = 'http://mywebsite.com';
}
}
window.addEventListener("load", countDown, false);
Upvotes: 0
Views: 190
Reputation: 1302
You would have to inject the countdown code into the loaded page. I'm not sure how chrome extensions work, so I can't help you there.
An easier way to do this would be to put the target page in an <iframe>
and then change the src
attribute of that instead. You can make the iframe the size of the entire window so it looks normal. The only problem is that you would lose control over the address bar (it wouldn't change to whatever you set src
to)
Upvotes: 0
Reputation: 4054
if( min==0 && sec=='00' )
Your min is an integer and not a string ('00'). You are only displaying it as a string.
Upvotes: 1