2
我已经使用document.cookie
设置了Cookie。 Google Chrome中的内容设置显示了Cookie。但是,document.cookie
打印时显示为空白字符串。这是为什么发生?Cookie正在设置中,但document.cookie为空
这里是我的代码
function setCookie(name,value,lifeTime,path,domain,secure){//lifetime in hours
{
var c_ = name +'='+escape(value)+'; ';
var life = new Date();
lifeTime<1&&lifeTime>0?life.setMinutes(life.getMinutes()+lifeTime*60):life.setHours(life.getHours()+lifeTime);
life = life.toUTCString();
c_+='expires='+life+"; ";
c_+= 'domain='+domain+'; ';
c_ += 'secure=secure; ';//secure
c_ += 'path='+path;
document.cookie = c_;
alert(document.cookie);
/*Just splitted the code instead of c = 'name='+value+'expires ='+life etc*/
}
如果您需要任何帮助,请告诉我们您的代码。 – Leo 2012-02-17 19:39:11
此脚本在哪里运行?内容脚本或背景/弹出? – yonran 2012-02-17 19:55:34