cooikie help

Results 1 to 2 of 2

Thread: cooikie help

  1. #1
    Join Date
    Dec 1969

    Default cooikie help

    i set a cookie on one page using javascript: <BR><BR>function setCookie() <BR>{ <BR>document.cookie = "RDuserInfo=" + escape(document.frmACDCapture.ContNameFirst.value + ";" + document.frmACDCapture.ContNameLast.value + ";" + document.frmACDCapture.ContWEmail1.value + ";" + document.frmACDCapture.AcctPhone1.value + ";" + document.frmACDCapture.AcctDesc.value) + "; expires = " + now; <BR>} <BR><BR>** the "expires=" + now set&#039;s the cookie to expire 10 years in the future (the value of the year in now has 10 added on to it)<BR><BR>I then try to read the cookie back in on another page using VBScript: <BR><BR>userVals = Request.Cookies("RDuserInfo") <BR><BR><BR><BR>but am unable to. I am able to read it with the same code on the page it was set on. Could this be because I did not specify a domain when the cookie was set? What needs to be set so that it can be read from any page on the site? <BR><BR>any help would be greatly appreciated.

  2. #2
    Join Date
    Dec 1969

    Default RE: cooikie help

    You can not read a cookie you set in js with vb. you need to read it with js and then pass it to vb. Here is some code to read a cookie in js.<BR><BR>var obj = document.cookie;<BR>getCookie("Bin")<BR><BR>functi on getCookie(name) {<BR> name += "="; // append &#039;=&#039; to name string<BR> var i = 0; // index of first name=value pair<BR> while (i &#060; obj.length) {<BR> var offset = i + name.length; // end of section to compare with name string<BR> if (obj.substring(i, offset) == name) { // if string matches<BR> var endstr = obj.indexOf(";", offset); // locate end of name=value pair<BR> if (endstr == -1) endstr = obj.length;<BR> Stamp = obj.substring(offset, endstr)<BR> }<BR> i = obj.indexOf(" ", i) + 1; // move i to next name=value pair<BR> if (i == 0) break; // no more values in cookie string<BR> }<BR>setCookie("Bin", Stamp)<BR>// If the is no cookie set one.<BR> }<BR><BR>// Then I have it redirect back to a page<BR>// so I can grab the info in VB.<BR><BR>window.location.href = ("Home.asp?UserID="+ Stamp)<BR><BR>}<BR><BR><BR>I hope this helps.<BR>jc<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts