473,809 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getD ay() + 365);

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

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

Menu.asp:
....
if Request.Cookies ("PersistentInf os")("langue" ) = "" then
Response.Cookie s("PersistentIn fos")("langue" ) = 0
Response.Cookie s("PersistentIn fos").Expires = Now + 365
end if

varLangue = Request.Cookies ("PersistentInf os")("langue" )
....
<a CLASS=clsMenuBl anc href=""
onclick="javasc ript:setCookie( 'PersistentInfo s=langue',
<%=varOtherLang ue%>);"><b><%=l angueLink %></a>
....

Cookie after the first load:

CookieMesAppli
UserNameIntrane t=userTest
devintranet/
1024
1426579456
29791664
1185569408
29789752
*
PersistentInfos
langue=0
devintranet/
1024
3190340608
29863177
1185569408
29789752
*
CookieSession
Prenom=no&Redir ection=0&Nom=no &Matricule=0
devintranet/
1024
1426579456
29791664
1220109408
29789752
*

cookie after the change language link click event:
CookieMesAppli
UserNameIntrane t=parrots
devintranet/
1024
1426579456
29791664
1185569408
29789752
*
CookieSession
Prenom=no&Redir ection=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 1970
JRS: In article <11************ **********@c74g 2000cwc.googleg roups.com>
, dated Mon, 12 Jun 2006 08:54:30 remote, seen in
news:comp.lang. javascript, Stef <st************ @mittalsteel.co m> 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.getD ay() + 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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
1704
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 along the lines of after the submit the first thing to do is save the text somewhere (cookie?) and then check for the presence of the cookie on the form page and if it exists load the text from it. Destroying the cookie after a successful insert....
2
2679
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 LCID being set to UK. I have googled extensively but can't work it out. This is my code to give write the current date/time to screen: <% Session.LCID = 2057 Response.Write Now() & "<br>" &
4
1660
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 values. But if I redirect to another page and read the cookie only 18 of the values remain. Even though I load the same 25 barcodes at login, the 18 that remain can differ each time.
4
3657
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 contain a bigger picture of the thumbnailed selected. The problem is that all these thumbnails (and the big picture) are placed quite far down in the document. (a lot of text is at the top.) What I want is that when a thumbnail is clicked, the...
3
11130
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 behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
1
6722
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 simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring. I'm sure the answer will help alot of others who are using this script, and would...
5
2229
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. I've been testing my code and for some reason, the cookie expires randomly before even 24 hrs has passed. Yesterday it expired after 11hrs and 20mins. Any idea why my cookie expiration isn't working?
2
6253
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 browse to a page on a server and if the content of the page is the following: <html> <head><script> alert(document.cookie);
27
6919
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 test the time zone offset on a variety of dates to see if it changes. Based on that, I developed the following checkDST() function which, as far as I can tell, should be sufficient. It checks either the date passed to it or the current date with...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.