ASP & Javascript Cookies

They have: 330 posts

Joined: Apr 2000

Is it possible to read a cookies set by ASP using javascript?

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

put them in a and read it with javascript.
Is that what you're asking?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Yes it is, but the cookie you create in ASP has to be the permanent kind (must specify expire date).

They have: 330 posts

Joined: Apr 2000

Yes, I am setting them to expired = Date + 1 which should make them available until midnight. Right? Is that what you meant?

How would I write this in javascript? The cookie name is "Access".

Thanks.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

I would use DateAdd instead:

Response.Cookies("Name").Expires = DateAdd("m",3,Now)

So this cookie would expire in 3 months.

Here's an example of a cookie in javascript:

function SetValue() {
     var expdate = new Date ();
     expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 365));
     setCookie ("CookieName", "CookieValue", expdate);
}

function setCookie (name, value, expires) {
     if (!expires) expires = new Date();
          document.cookie = name + "=" + escape (value) +
    "; expires=" + expires.toGMTString() +  "; path=/";
}
'

Then in ASP you would just request that cookiename.

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.