Saving cookie changes

S

Stef

Hi people,
I have a problem with cookies set via javascript. What I try to
achieve is, when a user comes on the intranet, he can click on a link (
a simple href) that will set the content to french or english. I want
to set a cookie to persist that choice each time the user comes back on
the intranet. This feature must be available everywhere on the
intranet and the link is placed in an inner asp script called Menu.asp
which is included each time a page loads.

Now, I know it's maybe not the best way to achieve this but I'm just
working from what has been made by others, I cannot change the way
things are made, too much work would be involved and they won't accept
to give time to do everything all over again.

The best approach I got was to set a querystring value and replace the
cookie value from vbscript code. The problem is, the intranet we have
use a lot of the querystrings for a lot of features and when I click
the English/French link, that info is lost. I've tried to set a
mechanism to keep all the querystring and only add a new value but I
got weird results...

So I've turned to Javascript and still got no luck... For some
reasons, the cookie gets deleted from the cookie file as soon as my
javascript modifies the cookie.

Here's an example:

Javascript:

.... //this code is from a post found on google

var bites = document.cookie.split("; ");

var today = new Date();
var expiry = new Date(today.getDay() + 365);

function setCookie(name, value)
{
// use: setCookie("name", value);
if (value != null && value != "")
{
document.cookie=name + "=" + escape(value) + "; expires=" +
expiry.toLocaleDateString();
}

bites = document.cookie.split("; "); // update cookie bites
}
....

Menu.asp:
....
if Request.Cookies("PersistentInfos")("langue") = "" then
Response.Cookies("PersistentInfos")("langue") = 0
Response.Cookies("PersistentInfos").Expires = Now + 365
end if

varLangue = Request.Cookies("PersistentInfos")("langue")
....
<a CLASS=clsMenuBlanc href=""
onclick="javascript:setCookie('PersistentInfos=langue',
<%=varOtherLangue%>);"><b><%=langueLink %></a>
....

Cookie after the first load:

CookieMesAppli
UserNameIntranet=userTest
devintranet/
1024
1426579456
29791664
1185569408
29789752
*
PersistentInfos
langue=0
devintranet/
1024
3190340608
29863177
1185569408
29789752
*
CookieSession
Prenom=no&Redirection=0&Nom=no&Matricule=0
devintranet/
1024
1426579456
29791664
1220109408
29789752
*

cookie after the change language link click event:
CookieMesAppli
UserNameIntranet=parrots
devintranet/
1024
1426579456
29791664
1185569408
29789752
*
CookieSession
Prenom=no&Redirection=0&Nom=no&Matricule=0
devintranet/
1024
1426579456
29791664
1220109408
29789752
*

I'm puzzled... If someone has a suggestion to do this better than I'm
trying right now, please do!

Thanks a lot for reading!
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Mon, 12 Jun 2006 08:54:30 remote, seen in
news:comp.lang.javascript said:
... //this code is from a post found on google

Much rubbish can be found that way.
var today = new Date();
var expiry = new Date(today.getDay() + 365);

that gives a date/time of between 365 and 371 milliseconds from
1970-01-01 00:00:00 GMT, which is unlikely to be what you want.

Read the newsgroup FAQ; see below.

D = new Date()
D.setFullYear(D.getFullYear()+1)

sows what you probably want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top