Hello everyone, I have this script and i don't know why doesn't work. I want to display a timer on page a index.html, after 15 sec, the page is reloaded and appears other content...how can I do that? <script type="text/javascript"> var cnt = 15; function countdown() { if (cnt == -1) { window.location.href = "index.html"; } else { /* min = Math.floor(cnt / 60); sec = cnt - (min * 60); if (sec < 10) { sec = "0" + sec; } if (min < 10) { min = "0" + min; } document.getElementById('timercountdown').innerHTML = min + ":" + sec; */ if (cnt <= 1) { measurement = "second"; } else { measurement = "seconds"; } document.getElementById('timercountdown').innerHTML = cnt + " " + measurement; cnt--; _timer = setTimeout("countdown()", 1000); } } var _timer = setTimeout("countdown()", 1000); // start ticking process </script> Please wait for another <span id="timercountdown"></span> while the page is loading... Click "here" if you want to start immediately.
<script type="text/javascript"> var cnt = 14; function countdown() { if (cnt <= 1) { measurement = "second"; } else { measurement = "seconds"; } if(cnt==-1){ window.location.href='http://google.com'; //document.getElementById('hidden').style.display="block"; //document.getElementById('timer').style.display="none"; }else{ document.getElementById('timercountdown').innerHTML = cnt + " " + measurement; cnt--; _timer = setTimeout("countdown()", 1000); } } var _timer = setTimeout("countdown()", 1000); // start ticking process </script> Please wait for another <span id="timercountdown">15 seconds</span> while the page is loading... Click "here" if you want to start immediately. Code (markup):
You do not understand me, I want to appear this countdown timer on a page "index.html" and after the counter reaches 0,the page is reloaded ,the counter disappears and other content appears on the same page (index.html)... The script that I posted above, it's something like when the counter reaches 0, the page is reloaded but it appears again, and I want to appears something else.
Do redirect to another page instead of reload the same page. Or pass a parameter in JS to URL and read it (best on server side) and return the same page without counter functionality.
index.html: <script type="text/javascript"> var cnt = 15; function countdown() { if (cnt == -1) { window.location.href = "index2.html"; } else { /* min = Math.floor(cnt / 60); sec = cnt - (min * 60); if (sec < 10) { sec = "0" + sec; } if (min < 10) { min = "0" + min; } document.getElementById('timercountdown').innerHTML = min + ":" + sec; */ if (cnt <= 1) { measurement = "second"; } else { measurement = "seconds"; } document.getElementById('timercountdown').innerHTML = cnt + " " + measurement; cnt--; _timer = setTimeout("countdown()", 1000); } } var _timer = setTimeout("countdown()", 1000); // start ticking process </script> Code (markup): index2.html Your page here Code (markup):