日期:2014-05-16  浏览次数:20446 次

JS怎么实现让页面载入后自动刷新一次
<meta http-equiv="refresh" content="1">   隔1秒刷新一次,这个是不停的刷新。

要起到上面这种刷新的效果,但只要刷一次就够了

------解决方案--------------------
<!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都没问题