【发布时间】:2014-08-20 06:23:55
【问题描述】:
我正在制作一个简单的重定向脚本,它将在 5 秒后将用户重定向到 2.html。
当我在 Chrome 上测试脚本并且它可以工作时!,但在最新的 Firefox 中,它并没有减少秒数并挂起。
我是初学者,已经尽我所能,但我无法解决这个问题,我上网查了一下,但无法找到解决方案。我该如何解决这个问题?
我的代码:
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>
控制台错误消息
- Firefox - 无
- 铬 - 无
输出:
-
火狐(永远):
Welcome <name> You are being redirected in 3 seconds
-
铬:
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
感谢任何帮助。
【问题讨论】:
-
@P5Coder 您使用哪个版本?
-
你添加了吗
Jquery library?? -
@AsheshKumar: 12.0.1
-
@Prashant 代码没有使用 Jquery 库。他写道,它可以在 Chrome 中运行。
标签: javascript html google-chrome firefox redirect