Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript & Cookies

Status
Not open for further replies.

GolfBoy

MIS
Sep 5, 2001
35
GB
How to I set a local variable with the value stored in a cookie on the window_onload() event in VBScript.

I read that you need to use string methods such as substring, charAt, indexOf, and lastIndexOf to determine the value stored in the cookie. But how ????

I tried the following

Sub
Window_onload()
Dim myparam

myparam = document.cookie[mycookie]

End sub


Any help would be great.


 
Cookie values are stored using the Response object like this:

Response.Cookies("name") = "Homer"

The value can be retrieved using the Request object in the onload event like this:

dim strName
Sub Window_OnLoad
strName = Request.Cookies("name")
end sub

Hope that helps!
 
It depends on where you are inspecting the cookie - on the Client (JavaScript) or on the Server (VBScript / JavaScript / others).

In the Client, you have the window_open event (not the server), so you would need to use string twiddling:

var sCookies;
var arrCookies;

sCookies = document.cookies; //get the cookies as a string
//multpile cookies separated with semi-colon
// ie "name=fred;job=programmer"

arrCookies = sCookies.split(";"); //split cookies into array
//each array element is "key=value"
//will need to extract the value for the required key.



But the same is much easier on the Server (See TurboSloth item above). It just depends on what you need to do! (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top