tags:

views:

123

answers:

4

I search Google but found entire functions to get cookie value. Isn't there one line statement to retrieve cookie value in javascript?

A: 

There isn't a "single statement". One possibility: document.cookie.

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
jldupont
+1  A: 

try document.cookie. Here is a good link

ram
That is the link I meant. I don't want to include those functions.
RPK
understood.Any specific reasons?
ram
+1  A: 

You could use a javascript library, e.g. jQuery in addition with a plugin: http://plugins.jquery.com/project/cookie

Demo page: http://stilbuero.de/jquery/cookie/

The MYYN
A: 

im sure there is a simplier way to get a cookie?

like all u gotta do to set one is like

document.cookie "cookiename=cookievalue";

there must be a way to read it as simple like

var cvalue = getcookie "cookiename"

Owen