Why does Chrome ignore local jQuery cookies?
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?
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.
对于本地应用程序,请在Chrome中使用localStorage:http://people.w3.org/mike/localstorage.html
i had some problem and solved it this terrible solution. using store and cookie plugin together.
<script src="js/jquery.cookies.2.2.0.js" type="text/javascript"></script>
<script src="js/jquery.Storage.js" type="text/javascript"></script>
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//get cookies
var helpFlag=(is_chrome)?$.Storage.get("helpFlag"):$.cookies.get("helpFlag");
//set cookies
if(is_chrome)$.Storage.set("helpFlag", "1");else $.cookies.set("helpFlag", "1");
I know that this isnt perfect solution but works for me
链接地址: http://www.djcxy.com/p/44886.html上一篇: 本地主机上带有显式域名的Cookie