I'm using the "jQuery Cookie Plugin" on my homepage but it doesn't work in only chrome. And I use only chrome too. help please
Asked
Active
Viewed 6,196 times
2 Answers
5
I have same 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 src="js/jquery.Storage.js" type="text/javascript">
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//get cookies
var myCookie=(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 isn't perfect but works for me.

Flexo
- 87,323
- 22
- 191
- 272

Serdar Güner
- 111
- 2
- 2
-1
You may find that using raw JavaScript rather than a plugin to achieve such a simple task will be faster and easier to manage cross-browsers.
The below code works in Chrome.
// Thanks to http://www.quirksmode.org/js/cookies.html for the below functions
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

jakeisonline
- 1,206
- 1
- 11
- 24
-
Was this answer helpful Shitic? Let me know if it's not what you needed and I'll adjust the answer for you. – jakeisonline Sep 27 '09 at 19:22
-
2-1 Cookies don't work on local files in Chrome regardless of the use of raw JavaScript – Tomas Jan 12 '11 at 13:56