<script type="text/javascript">

//建立一個cookie    
function createCookie(name,value,days) {
 if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "";
  expires=""+date.toGMTString();
 }
 else var expires = "";
 document.cookie = name + "=" + value + "; expires=" + expires;  

}

//讀取cookie
function GetCookie(name)
//讀取Cookie的原始值
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return GetCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function GetCookieVal(offset)
//獲得Cookie解码后的值
{
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


//刪除cookie
function DeleteCookie(name) {
 createCookie(name,"",-1);
}



</script>
example:
createCookie('ppkcookie','testcookie',7)
GetCookie('ppkcookie')

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 包爾伯 的頭像
    包爾伯

    人生過程精彩才是重點

    包爾伯 發表在 痞客邦 留言(0) 人氣()