注册 登录
编程论坛 PHP技术论坛

[求助]如何要页面在停留3秒后自动条转到首页!

yuexiayiyu 发布于 2007-05-19 14:22, 3073 次点击
如何要页面在停留3秒后自动条转到首页!关键是怎么设置时间的(3秒!)
5 回复
#2
yuexiayiyu2007-05-19 14:23
就象我们在这论坛帖时!发完后。提示3秒后自动跳转到发页面。!!
#3
lmhllr2007-05-19 16:56

<META HTTP-EQUIV="REFRESH" CONTENT="3; URL=http://www.bc-cn.net" />

#4
rainic2007-05-24 10:33

给个JS写的"倒数"类
countdown.js

function countdown() {
this.second = 0;
this.url = "";
this.idinterval = false;
this.isStop = false;
window.obj = this;
this.cd = function() {
this.second--;
if (this.second <= 0) {
window.location = this.url;
clearInterval(this.idinterval);
}
this.writesecond();
}
this.cd_start = function() {
if (document.getElementById("span_countdown") == null)
document.write("<span id=\"span_countdown\" style=\"color:#0066CC\">" + this.second + "</span>");
this.idinterval = setInterval("obj.cd()",1000);
}
this.cd_stop = function() {
clearInterval(this.idinterval);
}
this.writesecond = function() {
document.getElementById("span_countdown").innerHTML = this.second;
}
this.stop_and_goon = function() {
if (this.isStop) {
this.isStop = false;
this.cd_start();
}
else {
this.isStop = true;
this.cd_stop();
}
}
}

使用例子:
<script language="javascript" src="countdown.js"></script>

<script language="javascript">
var cd = new countdown();
cd.second = 9;
cd.url = "<?=$_GET['url']?>";
cd.cd_start();
</script>
秒后自动跳转
<p>
<a href="###" onclick="cd.stop_and_goon()">暂停|开始</a>

#5
islet2007-05-24 10:34
js问题也跑这里问。。。
#6
谁与争疯2007-05-24 12:40
是把问题复杂化了。

可以弄个简单一点的嘛。

<META HTTP-EQUIV="REFRESH" CONTENT="3; URL=<?php echo $url?>" />

但是、4楼版主的JS,能让用户自定暂停/开始,也是一个很实用的功能。
1