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:
So the cookie fails only for Google Chrome on local files.
Possible causes:
Can anyone confirm this and identify the root cause?
Click 'Internet options'. Click the 'Privacy' tab and then click the 'Advanced' button. Click the 'Override automatic cookie handling' option.
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
You cannot. By design, for security purpose, you can access only the cookies set by your site.
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 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.
For local applications use localStorage in Chrome instead: http://people.w3.org/mike/localstorage.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With