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

Posted on 2009-04-25
Last Modified: 2012-05-06
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

Response.Cookies("crystalsite-x")("username") = lUsername

Response.Cookies("crystalsite-x")("domain") = lDomain

Response.Cookies("crystalsite-x").Expires = Date() + 30

Open in new window

Question by:logicmedia
    LVL 29

    Accepted Solution

    Code on the pages:



    Author Comment

    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 ;
          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

    LVL 29

    Expert Comment

    Glad it helped. Kudos on your enhancement.



    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    gzip in express of nodejs 12 44
    Hide IE  and Firefox toolbar 5 37
    Time/Date Query 11 29
    Conditional Link URL - Easy Question 4 31
    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now