0

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

Shitic
  • 3
  • 1
  • 2

2 Answers2

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