Etienne
Etienne

Reputation: 7201

Reading cookie across directories

This is my JavaScript code I use to create 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?

Upvotes: 0

Views: 105

Answers (1)

Sean Kinsey
Sean Kinsey

Reputation: 38046

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();.

Upvotes: 1

Related Questions