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