www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem cookie Google chrome

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Problem cookie Google chrome

    I want to save cookie in Google Chrome. I wrote code which works in Firefox but not in chrome. What is wrong?


    function getCookie(name){
    var str = '; '+ document.cookie +';';
    var index = str.indexOf('; '+ escape(name) +'=');
    if (index != -1) {
    index += name.length+3;
    var value = str.slice(index, str.indexOf(';', index));
    return unescape(value);
    }
    }
    function setCookie(name, value, expires) {
    var cookieStr = escape(name) +"=";
    if (typeof value != "undefined") {
    cookieStr += escape(value);
    }
    if (!expires) {
    expires = new Date();
    expires.setTime(expires.getTime()+24*60*60*1000);
    }
    cookieStr += "; expires="+ expires.toGMTString() +";";
    document.cookie = cookieStr;
    }


    var zxc=0;
    //////////////////////


  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Quote Originally Posted by djspoko View Post
    I want to save cookie in Google Chrome. I wrote code which works in Firefox but not in chrome. What is wrong?
    What doesn't work?

    Does it fail to set, fail to read or both?

    I'm guessing it's the reader.

    Code:
    var str = '; '+ document.cookie +';';
    var index = str.indexOf('; '+ escape(name) +'=');
    This assumes that the wanted data is preceded by "; ", dictating that the first cookie in document.cookie will be ignored.
    I'm sure you'll want to find your own solution.

    Addendum: It seems that the current version of Chrome doesn't set cookies under the file:/// protocol. Other browsers have done this in the past, so you'll have to test it under http://.
    Last edited by clueful; 02-07-2011 at 05:51 PM.


    Q: I found this code...
    A: Then find its author.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles