设置cookie的方法,和获取cookie的方法如下
设置cookie
document.cookie="name="+value;
//获取cookie其中index是cookie的名称
function getCookie(index){
var allcookies = document.cookie;
var cookie_pos = allcookies.indexOf(index);
if (cookie_pos != -1){
cookie_pos += index.length + 1;
var cookie_end = allcookies.indexOf(";",cookie_pos);
if (cookie_end == -1){
cookie_end = allcookies.length;
}
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
}