为什么Chrome忽略本地jQuery cookie? [英] Why does Chrome ignore local jQuery cookies?

查看:112
本文介绍了为什么Chrome忽略本地jQuery cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是jQuery Cookie插件(下载 demo 带有注释的源代码)设置和读取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中设置Cookie (PC)。但如果浏览器是Google Chrome且网页是本地文件,则无效。

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一起使用。

  • 如果我将代码放在Web服务器上(以http://开头的地址),则可以与Chrome一起使用。

  • The plugin's demo works with Chrome.
  • If I put my code on a web server (address starting with http://), it works with Chrome.

因此,只有在本地文件上的Google Chrome 才会失败。

可能的原因<

Possible causes:


  • Google Chrome不接受硬碟上网页的Cookie(例如档案:/// C:/ websites / foo .html)

  • 插件插入中的某些内容会导致Chrome拒绝此类Cookie

推荐答案

Chrome不支持本地文件的cookie(或者像Peter Lyons提到的, localhost *),除非您使用--enable-file-cookies标志启动它。您可以在 http://code.google阅读有关此问题的讨论。 com / 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 http://code.google.com/p/chromium/issues/detail?id=535.

* Chrome IP地址(127.0.0.1)。所以在localhost的情况下,这可能是一个更容易的解决方法。

*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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆