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

【转】进入一个页面后 自动刷新一次的js代码
转自:http://bbs.csdn.net/topics/320137686

<!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">
        var Cookie = {
            setCookie:function(name,value,option){
                var str = name + "=" + escape(value);
                if(option){
                    if(option.expireDays){
                        var date = new Date();
                        var ms = option.expireDays * 24 * 3600 * 1000;
                        date.setTime(date.getTime() + ms);
                        str += "; expires=" + date.toGMTString();
                    }
                    if(option.path)str += ";path=" + option.path;
                    if(option.domain)str += ";domain=" + option.domain;
                    if(option.secure)str += ";true";
                }
                document.cookie = str;
            },
            getCookie:function(name){
                var cookies = document.cookie.split(";");
                for(var i=0; i<cookies.length;i++){
                    var arr=cookies[i].split("=");
                    if(arr[0]==name){
                        return unescape(arr[1]);
                    }
                }
                return "";
            },
            delCookie:function(name){
                this.setCookie(name,"",{expireDays:-1});
            }
        }
        window.onload=function(){
            if("1"==Cookie.getCookie("diffmaker")){
                alert("找到Cookie,我将不再刷新页面,并删除Cookie");
                Cookie.delCookie("diffmaker");
            }else{
                alert("没有找到Cookie,我将刷新页面!");
                Cookie.setCookie("diffmaker","1",null);
                window.location.reload(true);
            }
        }
    </script>
</head>
<body>
</body>
</html>

?