I am making a simple Redirect script that will redirect users to 2.html
after 5 seconds.
When I tested the script on Chrome and it works!, But in latest Firefox but it doesn't decrease seconds and hangs.
I am a beginner and have tried my best out of knowledge but I am unable to solve this, I looked online but was unable to find a solution. How can I solve this?
My code:
index.html:
<html>
<head>
<title>My First Page</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<input type="button" value=" YES " onclick="yes()" />
</body>
</html>
script.js:
c=5;
function yes() {
alert("Right");
var ans=0;
while(ans==0){
var x=prompt("Your Name?");
var ans=confirm("Your Name is "+x+" right?");
}
document.write('<h1>Welcome '+x+' </h1><p id="show">You are being redirected in 3 seconds</p>');
function updateShow(){
document.getElementById('show').innerHTML="<h1>You are being redirected in "+c+" seconds</h1>";
c=c-1;
if(c<0){
document.location='2.html';
}
else{
setTimeout(function(){ updateShow(); },1000);
}
}
var iAmTimer= setTimeout(function(){ updateShow(); },1000);
}
2.html:
<html>
<body>
<h1>Welcome</h1>
</body>
</html>
Console Error Messages
- Firefox - None
- Chrome - None
Output:
Firefox (forever):
Welcome <name>
You are being redirected in 3 seconds
Chrome:
Welcome <name>
You are being redirected in 3 seconds
Welcome <name>
You are being redirected in 2 seconds
Welcome <name>
You are being redirected in 1 seconds
Welcome <name>
You are being redirected in 0 seconds
Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…