2015年2月16日 星期一

html cookie 讀/寫/刪掉

function writeCookie(title,value,days)
{
    var expires = "";
    if(days)
    {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = ";expires=" + date.toGMTString();
    }
    document.cookie = title + "=" + value + expires + "; path = /";
}

function readCookie(title)
{
    var name = title + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) alert( c.substring(name.length,c.length));
    }
    return "";
}

function delCookie(title)
{
    writeCookie(title,"",-1);
}

code:
https://drive.google.com/file/d/0B8hm-I2M8BD7TmlmcE44bENNN2M/view?usp=sharing
請放在C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

沒有留言:

張貼留言