var caution = false    
function setCookie(name, value, expires, path, domain, secure) {    
        var curCookie = name + "=" + escape(value) +    
                ((expires) ? "; expires=" + expires.toGMTString() : "") +    
                ((path) ? "; path=" + path : "") +    
                ((domain) ? "; domain=" + domain : "") +    
                ((secure) ? "; secure" : "")    
        if (!caution || (name + "=" + escape(value)).length <= 4000)    
                document.cookie = curCookie    
        else    
                if (confirm("Cookie exceeds 4KB and will be cut!"))    
                        document.cookie = curCookie    
}    
function getCookie(name) {    
        var prefix = name + "="    
        var cookieStartIndex = document.cookie.indexOf(prefix)    
        if (cookieStartIndex == -1)    
                return null    
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)    
        if (cookieEndIndex == -1)    
                cookieEndIndex = document.cookie.length    
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))    
}    
function deleteCookie(name, path, domain) {    
        if (getCookie(name)) {    
                document.cookie = name + "=" +    
                ((path) ? "; path=" + path : "") +    
                ((domain) ? "; domain=" + domain : "") +    
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"    
        }    
}    
function fixDate(date) {    
        var base = new Date(0)    
        var skew = base.getTime()    
        if (skew > 0)    
                date.setTime(date.getTime() - skew)    
}    
var now = new Date()    
fixDate(now)    
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)    
var visits = getCookie("counter")    
if (!visits)    
        visits = 1    
else    
        visits = parseInt(visits) + 1    
setCookie("counter", visits, now)    
document.write("感谢您第 " + visits + " 次光临本站,欢迎您的到来!")//这段代码大概意思是检测访问网站的次数,我有很多地方不明白。首先是fixdate()不用行不?似乎在白忙活!第二个问题是settime ()参数中365*....有什么用先问这两个。谢谢啦!!!

解决方案 »

  1.   

    getTime 方法返回一个整数值,这个整数代表了从 1970 年 1 月 1 日开始计算到 Date 对象中的时间之间的毫秒数。日期的范围大约是 1970 年 1 月 1 日午夜的前后各 285,616 年。负数代表 1970 年之前的日期。fixdate感觉去了应该是也行。它的作用我看好象就是判断时间基准是不是小于零,但是好象都只是等于0,不知道有没有小的时候。
    now.getTime() + 365 * 24 * 60 * 60 * 1000前面这些意思就是距今天一年以后的日子。就是设cookie有效时间是1年。
      

  2.   

    第二个问题:
    设置cookie的有效期的时间;这样的表达式方便大家看清楚
      

  3.   

    就是过多长时间之后浏览器认为这个Cookie是失效的,失效之后就取不到了
      

  4.   

    谢谢各位的指点!!!stecookie()函数中形参有六个而实参有三个。难道javascript也支持c++中的默认参数吗???