javascript 本地 HTML 文件的 cookie 保存在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8602833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where are cookies saved for a local HTML file?
提问by dotNETbeginner
I created an HTML file on my desktop and added some JavaScript to set and clear cookies.
我在桌面上创建了一个 HTML 文件并添加了一些 JavaScript 来设置和清除 cookie。
Now my question is, will the cookie be saved in my browser? Can I read it back?
现在我的问题是,cookie 会保存在我的浏览器中吗?我可以读回去吗?
if Yes,
如果是,
For which domain will it be saved?
How can I see it in Google Chrome? (HTML run on Chrome)
它将保存在哪个域中?
我如何在 Google Chrome 中看到它?(HTML 在 Chrome 上运行)
回答by paulcol.
Unfortunately some browsers including Google Chrome do not store cookies from local web pages:
不幸的是,包括 Google Chrome 在内的一些浏览器不存储来自本地网页的 cookie:
Firefox has great developer plugins for cookie management, which report their domains, access paths and expiry:
Firefox 有很棒的 cookie 管理开发者插件,可以报告他们的域、访问路径和过期时间:
- https://addons.mozilla.org/en-US/firefox/addon/view-cookies/
- https://addons.mozilla.org/en-US/firefox/addon/firecookie/(Personal Favourite - Requires FireBug)
- https://addons.mozilla.org/en-US/firefox/addon/view-cookies/
- https://addons.mozilla.org/en-US/firefox/addon/firecookie/(个人最喜欢的 - 需要 FireBug)
For local development purposes you can setup a development domain like "localhost" or "myfakedomain.com" and run your files on a local server.
出于本地开发目的,您可以设置一个开发域,如“localhost”或“myfakedomain.com”,并在本地服务器上运行您的文件。
Search:
搜索:
- Editing Hosts File [operating system]
- Setup Local server on [operating system] (I use xampp)
- 编辑主机文件 [操作系统]
- 在 [操作系统] 上设置本地服务器(我使用 xampp)
回答by isNaN1247
If you're running the 'site' on a local webserver then it should be stored in your browser under 'localhost'. If however you're just opening a static HTML file Chrome will not store the cookie.
如果您在本地网络服务器上运行“站点”,那么它应该存储在浏览器中的“本地主机”下。但是,如果您只是打开一个静态 HTML 文件,Chrome 将不会存储 cookie。
In Chrome you can use the Chrome Developer Tools and look under the 'Resources' tab.
在 Chrome 中,您可以使用 Chrome 开发人员工具并查看“资源”选项卡。