I would like a line that says:
Your download will begin in (10, 9, 8, etc. Beginning on page load) seconds.
I already have the 10 second download text set up, and I have looked at other stackoverflow posts. They all include CSS, and Jquery. I would like just a Javascript/HTML timer.
No other requests have been made for a simple line stating "You're download will begin in x seconds". How would I do this?
A solution using Promises, includes both progress bar & text countdown.
JavaScript has built in to it a function called
setInterval
, which takes two arguments - a function,callback
and an integer,timeout
. When called,setInterval
will call the function you give it everytimeout
milliseconds.For example, if you wanted to make an alert window every 500 milliseconds, you could do something like this.
However, you don't have to name your function or declare it separately. Instead, you could define your function inline, like this.
Once
setInterval
is called, it will run until you callclearInterval
on the return value. This means that the previous example would just run infinitely. We can put all of this information together to make a progress bar that will update every second and after 10 seconds, stop updating.Alternatively, this will create a text countdown.
This does it in text.