473,378 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Saving cookie changes

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=lan gue',
<%=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!

Jun 12 '06 #1
1 1945
JRS: In article <11**********************@c74g2000cwc.googlegroups .com>
, dated Mon, 12 Jun 2006 08:54:30 remote, seen in
news:comp.lang.javascript, Stef <st************@mittalsteel.com> posted
... //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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill H | last post by:
I'm really new to Internet apps and such sorry, if this is a "duh" question. What is the standard approach to saving input from a form if on submit the database connection fails? I'm thinking...
2
by: Ian | last post by:
I have a problem I hope someone can point out where I am going wrong. I need to store a date/time in a cookie ( ie the date a visitor last visited ) However the date format changes to US, despite...
4
by: Wally | last post by:
I have a record set (rs) that contains 25 barcodes values that I set to true in a cookie. (see code section below) If I read the cookie from within the same page that created it, I see all 25...
4
by: ojorus | last post by:
Hi! I just wonder how I can save a page's scroll position with javascript. (i'm not a javascript developer) I have a PHP-page with two columns; the left contains a lot of thumbnails, and the right...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
1
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to...
5
by: SJ | last post by:
Hi, In my website, i have a cookie that allows the user to remain logged in for upto 90days. So I'm setting the cookie expiration time to 90 days in the future from the time the user logs in....
2
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
27
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.