views:

32

answers:

1

Say i have a file test.html that uses javascript cookies.

(a) When i access the file like this: http://mydomain.com/test.html cookies work fine.

(b) But if i just double click the file to directly open it in a browser (with a url like: file:///folder_path/test.html) then cookies do not work.

Is this the way it should be or am i doing something wrong?

Is there a solution for persistent storage in case (b) when you want to just open an html file and read some data from a previous session?

+4  A: 

That is the way it works. Cookies are saved with mydomain.com in the filename, and that is how they're accessed on future visits. So if you have a cookie then it can only be accessed again from the same server. Otherwise, any website would be able to read any of your cookies, and that's not a good thing ;)

If you want to read anything in a plain HTML file, you're going to be rather limited. I suppose if you use Internet Explorer you could write some VB Script to do the job for you but unless you tap into some sort of server-side technology you will have a hard time doing what you want.

Shawn Steward