开发者

Reading cookie across directories

This is my JavaScript code I use to c开发者_Go百科reate my cookie............

document.cookie = "Name=" + Name + ";expires=Friday, 31-Dec-2011 12:00:00 GMT; path/";

I create it in www.example.com/folder/file.html and it works.

But I cant read the cookie from www.example.com/index.html or www.example.com/folder2/file2.html.

What is wrong with my code?


you have an error in how you set the path

 path/ 

should be

path=/

Also, the format for the expiration date is wrong - it should be like Thu, 2 Aug 2001 20:47:11 UTC, the same format that is returned by new Date().toGMTString();.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜