Javascript“导出”所有饼干?
有一个很酷的 Firefox 扩展,它可以让您导出所有 cookie到 Netscape HTTP Cookies 文件 cookies.txt
,然后您可以将其与 wget
(等)一起使用,
这是一个示例 cookies.txt 文件
happycog.com
site:
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file! Do not edit.
cognition.happycog.com FALSE / FALSE 1345696044 exp_last_visit 998800044
cognition.happycog.com FALSE / FALSE 1345696044 exp_last_activity 1314160044
如何使用Javascript构建相同样式的“cookies导出”?当然,它只能读取当前域的 cookie。那就好了。
其他详细信息:
我意识到 cookie 无法使用纯 JavaScript 导出到文件系统。我很高兴将它们导出到文本区域或 document.write。我只是想知道如何以相同的格式获取它们,这样我基本上可以将它们复制并粘贴到 cookies.txt 文件中。不过,这里的挑战是使用 javascript 来完成,而不是使用插件。
There is a cool Firefox extension which lets you export all cookies to a Netscape HTTP Cookies File, cookies.txt
, which you can then use with wget
(et.al.)
Here is an example cookies.txt
file for the happycog.com
site:
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file! Do not edit.
cognition.happycog.com FALSE / FALSE 1345696044 exp_last_visit 998800044
cognition.happycog.com FALSE / FALSE 1345696044 exp_last_activity 1314160044
How can I build the same style "cookies export" with Javascript? Granted it would only be able to read cookies for the current domain. That would be just fine.
Additional Details:
I realize that cookies can't be exported to the file system with pure javascript. I'd be happy with them being exported to a textarea, or with document.write. I just want to know how I can get them in the same format where I can basically copy and paste them to a cookies.txt file. The challenge here is to do it with javascript, though, and not to use an addon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这会将您的 cookie 导出到键/值对数组中(例如 [ [key1, val1], [key2, val2], ...]),然后将其复制到剪贴板。它不会保留任何过期日期信息,因为无法通过 JavaScript 提取这些信息。
要重新导入 cookie,您需要运行以下代码:
This will export your cookies into an array of key/value pairs (eg. [ [key1, val1], [key2, val2], ...]), and then copy it to your clipboard. It will not retain any expiration date info because that's impossible to extract via Javascript.
To import the cookies back, you'd run the following code:
抱歉回复延迟了 - 必须睡觉了。我刚刚玩过这个,得出的结论是答案是否。
原因是 Javascript 无法访问除 cookie 名称和值之外的任何信息,您无法检索路径、到期时间等。您实际上想做什么?这是针对您正在开发的某个特定网站还是仅用于浏览时的一般用途?
Sorry about the delayed response - had to sleep. I have just been playing with this and concluded that the answer is NO.
The reason for this is that Javascript does not have access to any more information than the cookie's name and value, you can't retrieve the path, expiry time, etc etc. What do you actually want to do? Is this for one specific site you are developing or just for general use when browsing?
该页面的所有 cookie 都存储在
document.cookie
中All cookies for the page is stored in
document.cookie