/**
* 写入cookie
* @param name
* @param value
*/
function setCookie(cookieName,cookieValue){
document.cookie = cookieName + "="+ escape (cookieValue) + ";";
}
/**
* 读取cookie
* @param cookieName
* @returns
*/
function getCookie(cookieName){
if (document.cookie.length>0){
/**通过String对象的indexOf()来检查这个cookie是否存在,不存在就为 -1**/
var c_start = document.cookie.indexOf(cookieName + "=");
if (c_start != -1){
/**最后这个+1其实表示"=",获取到cookie值的开始位置**/
c_start = c_start + cookieName.length + 1;
var c_end = document.cookie.indexOf(";",c_start);
if (c_end == -1) c_end=document.cookie.length;
/**通过substring()得到值**/
var cookieValue = unescape(document.cookie.substring(c_start,c_end));
return cookieValue;
}
}
return null;
}