JS怎么实现让页面载入后自动刷新一次

sunshengxiong 2011-11-23 01:54:35
<meta http-equiv="refresh" content="1"> 隔1秒刷新一次,这个是不停的刷新。

要起到上面这种刷新的效果,但只要刷一次就够了
...全文
60216 46 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
46 条回复
切换为时间正序
请发表友善的回复…
发表回复
netcloud2 2014-03-05
  • 打赏
  • 举报
回复
if(!window.name){ window.name = 'test'; window.location.reload(); } 这个代码最简单了!这个没有延时,如果要延时的话把setTimeout放在if中,在else中放clearTimeout
xuanyuanqiansql 2013-12-18
  • 打赏
  • 举报
回复
引用 26 楼 ifandui 的回复:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
    <script type="text/javascript">
    String.prototype.queryString= function(name) {
	var reg=new RegExp("[\?\&]" + name+ "=([^\&]+)","i"),r = this.match(reg);
	return r!==null?unescape(r[1]):null;
};
    window.onload=function(){
        var last=location.href.queryString("_v");
        document.body.innerHTML+=last||"";
        if(location.href.indexOf("?")==-1){
            location.href=location.href+"?_v="+(new Date().getTime());
        }else{
            var now=new Date().getTime();
            if(!last){
                location.href=location.href+"&_v="+(new Date().getTime());
            }else if(parseInt(last)<(now-1000)){
                location.href=location.href.replace("_v="+last,"_v="+(new Date().getTime()));
            }
        }
    };
    </script></head>
<body>

</body>
</html>
alert如果你点慢了效果有差异,把alert去掉 时间改成1000毫秒在chrome下效果还行 chrome页面刷新之后的onload有时间延迟,IE改500都没问题
一般的小页面没事 但是到首页的时候(可能JS比较多有冲突),就会一直刷新,请问有什么好的解决方案么。谢谢 QQ4043097
小小流浪猫 2012-07-16
  • 打赏
  • 举报
回复
<script>
function reurl(){

url = location.href; //把当前页面的地址赋给变量 url

var times = url.split("?"); //分切变量 url 分隔符号为 "?"

if(times[1] != 1){ //如果?后的值不等于1表示没有刷新

url += "?1"; //把变量 url 的值加入 ?1

self.location.replace(url); //刷新页面

}
}

reurl();//执行这个函数
</script>
AIYAYIYAYO 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 ifandui 的回复:]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题……
[/Quote]太帅了
php9527 2011-11-29
  • 打赏
  • 举报
回复
window.location.reload();
opmic 2011-11-29
  • 打赏
  • 举报
回复
尼玛。。。。
bucce 2011-11-29
  • 打赏
  • 举报
回复
将一次载入和刷新绑定,可以在容器中存起来;然后判断是否存在,如果存在绑定就刷新一次。
xdspower 2011-11-29
  • 打赏
  • 举报
回复
刷新一次就停你可以借助cookie之类的啊。
不过我很奇怪你有这样的要求。
钱币老顽童 2011-11-26
  • 打赏
  • 举报
回复
顶贴要加分~\(≧▽≦)/~啦啦啦
九月 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 35 楼 why213344 的回复:]

我想知道你为什么加载就刷新一次?
[/Quote]

应该是缓存问题吧 算是强制刷新~~
卢剑仲 2011-11-24
  • 打赏
  • 举报
回复
新人,新人,快结贴。
why213344 2011-11-24
  • 打赏
  • 举报
回复
我想知道你为什么加载就刷新一次?
默默不得鱼 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 ohmysee 的回复:]
location 的应用(页面载入后自动刷新一次)
[/Quote]这怎么还没结贴,另外 兄弟你这不对 刷新之后再F5你就不会动弹了
sunshengxiong 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 ifandui 的回复:]

引用 25 楼 sunshengxiong 的回复:
试过了,谷歌IE都在不停的刷新,呵呵
得 我这边各个浏览器都测了没问题 不再关注了 群众眼睛是雪亮的
[/Quote]


最后经过测试完全没问题,非常感谢!!!
sunshengxiong 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 ifandui 的回复:]

引用 25 楼 sunshengxiong 的回复:
试过了,谷歌IE都在不停的刷新,呵呵
得 我这边各个浏览器都测了没问题 不再关注了 群众眼睛是雪亮的
[/Quote]

不是吧,崩溃了
sunshengxiong 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 dencey 的回复:]

引用 19 楼 sunshengxiong 的回复:

引用 17 楼 ifandui 的回复:

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xml……
[/Quote]

11楼没任何反应
默默不得鱼 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 sunshengxiong 的回复:]
试过了,谷歌IE都在不停的刷新,呵呵
[/Quote]得 我这边各个浏览器都测了没问题 不再关注了 群众眼睛是雪亮的
默默不得鱼 2011-11-23
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript">
String.prototype.queryString= function(name) {
var reg=new RegExp("[\?\&]" + name+ "=([^\&]+)","i"),r = this.match(reg);
return r!==null?unescape(r[1]):null;
};
window.onload=function(){
var last=location.href.queryString("_v");
document.body.innerHTML+=last||"";
if(location.href.indexOf("?")==-1){
location.href=location.href+"?_v="+(new Date().getTime());
}else{
var now=new Date().getTime();
if(!last){
location.href=location.href+"&_v="+(new Date().getTime());
}else if(parseInt(last)<(now-1000)){
location.href=location.href.replace("_v="+last,"_v="+(new Date().getTime()));
}
}
};
</script></head>
<body>

</body>
</html>

alert如果你点慢了效果有差异,把alert去掉 时间改成1000毫秒在chrome下效果还行
chrome页面刷新之后的onload有时间延迟,IE改500都没问题
加载更多回复(25)

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧