[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Read a cookie using javascript that has been set by a ASP script

Hi there,

This is probaly a simple question, but javascript and cookies is not what I have been using the most so far.

I have a cookie which has been set by the ASP code below.

How do I retrieve the username and domain values fra client side javascript code on a different page?

Thanks in advance

Thomas
Response.Cookies("crystalsite-x")("username") = lUsername
Response.Cookies("crystalsite-x")("domain") = lDomain
Response.Cookies("crystalsite-x").Expires = Date() + 30

Open in new window

0
logicmedia
Asked:
logicmedia
  • 2
1 Solution
 
rdivilbissCommented:
Code on the pages:

Demo: http://www.rodsdot.com/ee/CookieSetAsp.asp

Regards,
Rod
0
 
logicmediaAuthor Commented:
Hi there,

it works! Thanks.

I ended up with at modified script that can extract a parameter as well.

The second parameter is optinal
function getCookie(c_name, c_par)
{
  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
 
			if (typeof(c_par) != "undefined") {
		  	return getPar(c_par, unescape(document.cookie.substring(c_start,c_end)));
		  } else {
			  return unescape(document.cookie.substring(c_start,c_end));
			}
    } 
  }
  return ""
}

Open in new window

0
 
rdivilbissCommented:
Glad it helped. Kudos on your enhancement.

Regards,
Rod

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now