JavaScript 5 Seconds Countdown
Submitted by GeePee on Monday, March 30, 2015 - 23:33.
This code will allow you to add a 5 seconds countdown to the download page of your site. Depending on how you code your download page, the following will simply add a label within your body tag as:
"Download will start in 5 seconds"
Controlled by JavaScript using the span tag.
This is similar to the site at sourceforge.net. When you download something on that site, you will be redirected to another page and give you a countdown before you receive the file.
Here's the full code for you to play with. Hope you will like it.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script language="javascript">
- var max_time = 5;
- var cinterval;
- function countdown_timer(){
- // decrease timer
- max_time--;
- document.getElementById('countdown').innerHTML = max_time;
- if(max_time == 0){
- clearInterval(cinterval);
- }
- }
- // 1,000 means 1 second.
- cinterval = setInterval('countdown_timer()', 1000);
- </script>
- </head>
- <body>
- </body>
- </html>
Comments
Add new comment
- Add new comment
- 768 views