一进页面或者一返回页面就让页面刷新的方法

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");
      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-500)){
                    location.href=location.href.replace("_v="+last,"_v="+(new Date().getTime()));
             }
       }
};

posted @ 2016-10-13 09:25  轻风飞扬545  Views(269)  Comments(0)    收藏  举报