如何使用javascript获取浏览器存储的cookie
我对使用 javascript 访问所有浏览器 cookie 有疑问,我能够在 shell 脚本中执行此操作,但我想访问存储在本地计算机中需要传递到服务器的 cookie 信息。
问候
I have question regarding accessing all browser cookies using javascript, i was able to do this in shell script but i want to access the cookie information stored in local machine which needs to pass to server.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用以下方式访问它们
You can access them using
您无法访问所有浏览器cookie。仅为当前域设置 cookie,并且未标记为“仅限 http”(如果您位于非 SSL 页面,则为“安全”)。
在 javascript 中使用
document.cookies
更新
浏览器具有内置功能(作为安全功能),可防止您读取跨域 cookie。只要 javascript 在浏览器中运行,就没有方法访问这些 cookie,更不用说执行 shell 命令了。 Google 搜索:同源政策。
您基本上正在寻找的内容具有如此多的安全/隐私影响,我什至不知道从哪里开始解释危险。
You cannot access all browser cookies. Only cookies set for the current domain and not marked 'http-only' (or 'secure' if you are on a non-SSL page).
In javascript use
document.cookies
Update
The browser has built in functionality, as a security feature, to prevent you from reading cross domain cookies. As long as the javascript runs in the browser, there is no method to access those cookies, let alone execute a shell command. Google for: same origin policy.
What you basically are looking for has so many security/privacy implications, I don't even know where to start explaining the dangers.
想象一下这是可能的。您浏览到加载第三方广告的任意网站,流氓广告会读取您所有的浏览器 cookie,瞧!俄罗斯黑手党的某个人拥有您所有网站的“记住我”cookie 和会话 ID。他可以阅读您的电子邮件、在 Facebook 上查看您的照片并从您的 PayPal 帐户中取回资金。
Imagine that was possible. You browse to an arbitrary site that loads third-party ads, a rogue ad reads all your browser cookies and, voilá!, some guy from the Russian Mafia has the "Remember me" cookies and session IDs for all your sites. He can read your e-mail, see your pics on Facebook and retrieve money from your PayPal account.