javascript cookies

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cleary1981
    New Member
    • Jun 2008
    • 178

    javascript cookies

    Hi,

    I have set two cookies in my previous page. When I use an alert to show the value of the cookies this is the format I get.

    auth=1;project= 4

    I wan to use javascript to get the value of the project cookie. Does anyone know of a way I can do this?
    Last edited by cleary1981; Aug 20 '08, 02:17 PM. Reason: using different method
  • cleary1981
    New Member
    • Jun 2008
    • 178

    #2
    Ive worked it out using a split function

    here it is

    Code:
    var cokie = document.cookie;
    // alert(cokie);
    var splitCookie = cokie.split("=");
    	var proj = splitCookie[2]; // this is the value of proj_id extracted from the cookie
    	// alert(proj);

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      That would assume that the project value is always the second item in the cookie. If you want something more reliable, try the scripts in either this link or this one.

      Comment

      Working...