Refresh page when timer reaches 0 in JavaScript
<form name="counter" ><input type="text" size="8" name="d2"></form>
<script>
var milisec=0
var seconds={$wait}
document.counter.d2.value='{$wait}'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
document.title=seconds+"."+milisec
setTimeout("display()",100)
}
if (document.counter.d2.value==0){
location.reload(true)
}
display(开发者_如何转开发)
</script> <br />
{$time}
is the amount of seconds the counter start with. When it reaches 0 I want the page to reload. I tried :
if (document.counter.d2.value==0){
location.reload(true)
}
but that didn't work..
<form name="counter" ><input type="text" size="8" name="d2"></form>
<script>
var milisec=0
var seconds={$wait}
document.counter.d2.value='{$wait}'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
document.title=seconds+"."+milisec
setTimeout("display()",100)
}//<-mistake
if (document.counter.d2.value=="0.0"){ //<- mistaked
location.reload(true)
}
} //<- must be here
display()
</script> <br />
Does this work for you?
if (document.counter.d2.value==0){
window.counter.submit();
}
To reload page, you have to submit a form.
精彩评论