为什么 Chrome 会忽略本地 jQuery cookie?

编程入门 行业动态 更新时间:2024-10-28 18:31:20
本文介绍了为什么 Chrome 会忽略本地 jQuery cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 jQuery Cookie 插件(download 和 演示 和 带有注释的源代码) 来设置和读取 cookie.我正在本地机器上开发页面.

I am using the jQuery Cookie plugin (download and demo and source code with comments) to set and read a cookie. I'm developing the page on my local machine.

以下代码将在 FireFox 3、IE 7 和 Safari (PC) 中成功设置 cookie.但是如果浏览器是谷歌浏览器并且页面是本地文件,则它不起作用.

The following code will successfully set a cookie in FireFox 3, IE 7, and Safari (PC). But if the browser is Google Chrome AND the page is a local file, it does not work.

$.cookie("nameofcookie", cookievalue, {path: "/", expires: 30});

我所知道的:

  • 该插件的演示适用于 Chrome.
  • 如果我将代码放在网络服务器上(地址以 开头),它就可以在 Chrome 中使用.
  • The plugin's demo works with Chrome.
  • If I put my code on a web server (address starting with ), it works with Chrome.

因此 cookie 仅在本地文件上的 Google Chrome 浏览器失败.

So the cookie fails only for Google Chrome on local files.

可能的原因:

  • Google Chrome 不接受来自硬盘驱动器上网页的 cookie(路径如 file:///C:/websites/foo.html)
  • 插件实现中的某些内容导致 Chrome 拒绝此类 cookie

谁能确认这一点并找出根本原因?

Can anyone confirm this and identify the root cause?

推荐答案

Chrome 不支持本地文件的 cookie(或者像 Peter Lyons 提到的 localhost*),除非你用 --enable-file-cookies 启动它旗帜.您可以在 code.google 上阅读有关它的讨论/p/chromium/issues/detail?id=535.

Chrome doesn't support cookies for local files (or, like Peter Lyons mentioned, localhost*) unless you start it with the --enable-file-cookies flag. You can read a discussion about it at code.google/p/chromium/issues/detail?id=535.

*Chrome 确实支持 cookie.所以在本地主机的情况下,这可能是一个更简单的解决方法.

*Chrome does support cookies if you use the local IP address (127.0.0.1) directly. so in the localhost case, that could be an easier workaround.

更多推荐

为什么 Chrome 会忽略本地 jQuery cookie?

本文发布于:2023-10-29 17:14:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Chrome   jQuery   cookie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!