1、写Cookie时添加路径:
//写cookies,设置过期时间为30天,并设置path为根目录 function setPathCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + "; path=/";
}
2、删除Cookie时带上路径:
//删除根目录cookie function delPathCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString() + "; path=/"; }