function setCookie(c_name,c_value,days)//存入cookie的名稱,值,存活天數

{

var now = new Date( );

 

if(days == "" || days == null || days == undefined)//取未輸入預設為30天

now.setTime(now.getTime( ) + 1000 * 60 * 60 * 24 * 30);

else

now.setTime(now.getTime( ) + 1000 * 60 * 60 * 24 * days);

 

document.cookie = c_name + "=" + escape(c_value) + ";expires=" + now.toGMTString();

 

}

 

function getCookie(c_name)

{

var c_start = 0;

var c_end = 0;

 

if (document.cookie.length > 0)

{

c_start = document.cookie.indexOf(c_name + "=");

if (c_start != -1)

{

c_start = c_start + c_name.length + 1 ;

c_end = document.cookie.indexOf(";",c_start);

if (c_end == -1)

c_end = document.cookie.length;

 

return unescape(document.cookie.substring(c_start,c_end));

}

}

return "";

}

arrow
arrow
    文章標籤
    javascript cookie
    全站熱搜

    ixdezive19 發表在 痞客邦 留言(0) 人氣()