PDA

View Full Version : Refresh page Script - stop/start toggle button



bayswater
02-20-2008, 12:02 PM
1) Script Title: Refresh page Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex6/refresh.htm

3) Describe problem:
Is there a way to insert a stop-button or stop-link that you could toggle between "Stop countdown" and "Restart countdown"? I can't quite figure that out... :confused:

jscheuer1
02-20-2008, 05:18 PM
<script type="text/javascript">

//Refresh page script- By Brett Taylor (glutnix@yahoo.com.au)
//Modified by Dynamic Drive for NS4, NS6+
//Visit http://www.dynamicdrive.com for this script

//configure refresh interval (in seconds)
var countDownInterval=60;
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200

</script>


<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>

<script type="text/javascript">

var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b>');
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}

function stopRestart(el){
clearTimeout(counter);
if(el.value=='Stop')
el.value='Reset';
else{
countDownTime=countDownInterval+1;countDown();
el.value='Stop';
}
}

function startit(){
if (document.all||document.getElementById){ //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
document.write('<br><input type="button" onclick="stopRestart(this);" value="Stop">');
}
countDown()
}

if (document.all||document.getElementById)
startit()
else
window.onload=startit

</script>

bayswater
02-21-2008, 08:31 AM
Thanks a lot!