Why does Chrome ignore local jQuery cookies?

2018-12-31 22:41发布

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.

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});

What I know:

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

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

Possible causes:

  • Google Chrome doesn't accept cookies from web pages on the hard drive (paths like file:///C:/websites/foo.html)
  • Something in the plugin implentation causes Chrome to reject such cookies

Can anyone confirm this and identify the root cause?

8条回答
心情的温度
2楼-- · 2018-12-31 23:06

I had the same issue, please try using the IP address of localhost instead. For e.g "http://127.0.0.1/yoursite/"

查看更多
牵手、夕阳
3楼-- · 2018-12-31 23:22

This did the job for me:

enter image description here

Right click on your Chrome Icon and select Properties, Shortcut tab and add --enable-file-cookies at the last of the target path.

查看更多
登录 后发表回答