Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Setting Cookies using JavaScript in a local html file

I have the following directory tree:

+ folder1
|--- folder2
|------ page1.html
|--- page2.html

If I set some cookie in page1.html using JavaScript, what is the path used for that cookie?

Edit:
Let me explain it better. I'm working with a local file. page1.html is being accessed through /home/user/.../folder1/folder2/page1.html and not through a client machine using a HTTP Server.

Just to clarify:
It seems that some browsers (like Chrome) do not store cookies when using file:///, but both Firefox and Internet Explorer do.

question from:https://stackoverflow.com/questions/6232331/setting-cookies-using-javascript-in-a-local-html-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the MDC page for document.cookie:

If not specified, [the path argument] defaults to the current path of the current document location.

So in your case, it will be /folder1/folder2/.


I didn't initially see that you'd specified "local" in the question title -- not sure if this was updated while I was writing my answer. Cookies are not set when browsing using the file:/// protocol, depending on the browser.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...