<script>
var countdownFrom = 5; // number of seconds
var countdownwin;
function CountDownPopup() {
countdownwin = window.open("about:blank","","height=200,width=200"
self.setInterval('CountDownTimer()',1000)
}
function CountDownTimer()
{
if (countdownFrom==0) {countdownwin.close(); window.close(); }
else {
doc = countdownwin.document;
doc.open('text/html');
doc.write("Closing in "+countdownFrom+" seconds"
doc.close();
}
countdownFrom--
}
</script>
just call CountDownPopup() to start the countdown. This script doesnt check to see if the popup contdown window has been closed during the countdown, this is something you may wanna add to the code.
Yeah you could replace it with an area on the page in a Div Tag Span Tag or anything with an ID (Layer for netscape4)
somewhere in your HTML
<Div id="CountDownTime"></div>
replace CountDownPopup() with:
var stp;
function CountDownStart() {
stp = setInterval("CountDownTimer('CountDownTime')",1000)
}
then replace the CountdownTimer() with
function CountDownTimer(id)
{
if (countdownFrom==0) {clearInterval(stp); window.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; }
}
countdownFrom--
}
This code will work for IE and N6 but not N4.x, if you are supporting Netscrap4 good luck mate!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
<Div id="CountDownTime"></div>
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); window.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; }
}
countdownFrom--
}
Only joking, simple mistake, put the div tag in between the Body tags (which is where all your actual content HTML is meant to go) and call the CountDownStart() function in the body onload, so just cut n paste the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
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); window.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; }
}
countdownFrom--
}
Sorry so late on this one, but here's a cross-browser solution that should work in IE, NS4.x & NS6+:
[tt]
<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>
[/tt] Paul Ellis I've been programming since you had to punch holes in cards to code. (Always remember, number your cards!)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.