Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Script Countdown + Redirect

Status
Not open for further replies.

TwilightLinkable

Programmer
Apr 17, 2013
1
US
Hello there. I was able to find this code:


<html>
<head>
<title>Countdown Test</title>
<script type="text/javascript">
<!--
var countdownFrom=5; // number of seconds
var countdownwin;
var stp;

function CountDownStart(){
stp=setInterval("CountDownTimer('CountDownTime')",1000)
}

function CountDownTimer(id){
if(countdownFrom==0){
clearInterval(stp);
self.close();
}else{
var x;
var cntText='Closing in '+countdownFrom+' seconds';
if(document.getElementById){
x=document.getElementById(id);
x.innerHTML=cntText;
}else if(document.all){
x=document.all[id];
x.innerHTML=cntText;
}else if(document.layers){
x=document.NNCountDownTime;
x.document.write(cntText);
x.document.close();
}
}
countdownFrom--;
}
//-->
</script>
</head>
<body>
<div id="CountDownTime"><layer name="NNCountDownTime"></layer></div>

<script type="text/javascript">
<!--
window.onload=CountDownStart;
//-->
</script>
</body>
</html>


From this thread:


It works grate but I wanna have the viewer that is on the current web page to be redirected to a link that I linked them to. Also, is there an option where I can remove the timer visual from the web page and have it just say "Please Wait..."? That would be wonderful. Thanks!
 
Yes, Just remove the x.innerHTML=cntText; to remove the onscreen timer, and issue a change in location when the timer is up.

Code:
[COLOR=#990000]<[/color]html[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]head[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]title[COLOR=#990000]>[/color]Countdown Test[COLOR=#990000]</[/color]title[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]script type[COLOR=#990000]=[/color][COLOR=#FF0000]"text/javascript"[/color][COLOR=#990000]>[/color]
[COLOR=#990000]<!--[/color]
[b][COLOR=#0000FF]var[/color][/b] countdownFrom[COLOR=#990000]=[/color][COLOR=#993399]5[/color][COLOR=#990000];[/color] [i][COLOR=#9A1900]// number of seconds[/color][/i]
[b][COLOR=#0000FF]var[/color][/b] countdownwin[COLOR=#990000];[/color]
[b][COLOR=#0000FF]var[/color][/b] stp[COLOR=#990000];[/color]
[b][COLOR=#0000FF]var[/color][/b] url [COLOR=#990000]=[/color][i][COLOR=#009900] "[URL unfurl="true"]http://server.com/link/to/redirect";[/URL][/color][/i]

[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]CountDownStart[/color][/b][COLOR=#990000]()[/color][COLOR=#FF0000]{[/color]
stp[COLOR=#990000]=[/color][b][COLOR=#000000]setInterval[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"CountDownTimer('CountDownTime')"[/color][COLOR=#990000],[/color][COLOR=#993399]1000[/color][COLOR=#990000])[/color]
[COLOR=#FF0000]}[/color]

[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]CountDownTimer[/color][/b][COLOR=#990000]([/color]id[COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color]countdownFrom[COLOR=#990000]==[/color][COLOR=#993399]0[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[b][COLOR=#000000]clearInterval[/color][/b][COLOR=#990000]([/color]stp[COLOR=#990000]);[/color]
[b]window[COLOR=#990000].[/color]location [COLOR=#990000]=[/color] url[COLOR=#990000];[/color][/b]
self[COLOR=#990000].[/color][b][COLOR=#000000]close[/color][/b][COLOR=#990000]();[/color]
[COLOR=#FF0000]}[/color][b][COLOR=#0000FF]else[/color][/b][COLOR=#FF0000]{[/color]
[b][COLOR=#0000FF]var[/color][/b] x[COLOR=#990000];[/color]
[b][COLOR=#0000FF]var[/color][/b] cntText[COLOR=#990000]=[/color][COLOR=#FF0000]'Closing in '[/color][COLOR=#990000]+[/color]countdownFrom[COLOR=#990000]+[/color][COLOR=#FF0000]' seconds'[/color][COLOR=#990000];[/color]

countdownFrom[COLOR=#990000]--;[/color]
[COLOR=#FF0000]}[/color]
[i][COLOR=#9A1900]//-->[/color][/i]
[COLOR=#990000]</[/color]script[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]head[COLOR=#990000]>[/color]
[COLOR=#990000]<[/color]body[COLOR=#990000]>[/color]


[COLOR=#990000]<[/color]script type[COLOR=#990000]=[/color][COLOR=#FF0000]"text/javascript"[/color][COLOR=#990000]>[/color]
[COLOR=#990000]<!--[/color]
window[COLOR=#990000].[/color]onload[COLOR=#990000]=[/color]CountDownStart[COLOR=#990000];[/color]
[i][COLOR=#9A1900]//-->[/color][/i]
[COLOR=#990000]</[/color]script[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]body[COLOR=#990000]>[/color]
[COLOR=#990000]</[/color]html[COLOR=#990000]>[/color]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top