Forum Moderators: open

Message Too Old, No Replies

Retrieve Simple Javascript Cookie by name

         

JAB Creations

4:44 am on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a cookie I set by the name "counter". All I want to do with javascript is say, get the cookie "counter" and print it's value.

The problem I'm facing is that everything is overcomplicated. I can't find any way to simply call a cookie by name and then document.write it's value.

JAB Creations

5:39 am on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can do what I want but in PHP and I need to do it in Javascript...

Here is the PHP...

if ($HTTP_COOKIE_VARS[cookie_name_hereh]=="0") { }

dcrombie

11:49 am on Jun 10, 2005 (gmt 0)



Here's one I prepared earlier:

function getCookie(name) { // use: getCookie("name"); 
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value!= null)? unescape(value[1]) : null;
}

;)

RonPK

12:23 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is multiposting [webmasterworld.com] a TOS violation?