473,386 Members | 1,835 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,386 software developers and data experts.

"Setting" a Cookie

Don
I understand that when I send a cookie in a client-side page containing JS, it isn't actually "set"
until the next page is loaded. Is there some way to "set" it within the same html/JS page so it can
be accessed by other JS scripts in the same page?

Thanks,
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 23 '05 #1
9 1352
Don wrote on 13 feb 2005 in comp.lang.javascript:
I understand that when I send
You mean "set" I hope?
a cookie in a client-side page
containing JS, it isn't actually "set" until the next page is loaded.
Is there some way to "set" it within the same html/JS page so it can
be accessed by other JS scripts in the same page?

That would mean that if your first page is loaded and then you trip over
the power cable, disconnecting the pc, the cookie would not be set?

Seems very improbable to me.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #2
Don
On 13 Feb 2005 14:17:11 GMT, "Evertjan." <ex**************@interxnl.net> wrote:
Don wrote on 13 feb 2005 in comp.lang.javascript:
I understand that when I send


You mean "set" I hope?
a cookie in a client-side page
containing JS, it isn't actually "set" until the next page is loaded.
Is there some way to "set" it within the same html/JS page so it can
be accessed by other JS scripts in the same page?

That would mean that if your first page is loaded and then you trip over
the power cable, disconnecting the pc, the cookie would not be set?

Seems very improbable to me.

My tests seem to verify what I've read, and that is that the browser doesn't actually "set" the
cookie until it encounters a subsequent page requiring its use. So, I suspose your theory that it
wouldn't be set it the pc lost power would be true.

Putting that aside, and assuming the foregoing is true, I'm looking for a way to force the browser
to set it in the same page containing the JS statement that attempts to set it.

Thanks,
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 23 '05 #3
Don wrote on 13 feb 2005 in comp.lang.javascript:
That would mean that if your first page is loaded and then you trip
over the power cable, disconnecting the pc, the cookie would not be
set?

Seems very improbable to me. My tests seem to verify what I've read, and that is that the browser
doesn't actually "set" the cookie until it encounters a subsequent
page requiring its use.


How did you test that, Don?
So, I suspose your theory that it wouldn't be
set it the pc lost power would be true.
Well I don't, offhand.
Putting that aside, and assuming the foregoing is true,
I would not assume that.
Please tell me what you mean by "set" in this case:
That the cooky file is placed in the IE temp structure?

What if that 'next page' is accessed a month later and the browser has
been closed down inbetween. Would you suggest that the cookie [one with
an expiry date, I mean, of course] is lost then?

That is contrary to my experience.

If it is not lost and not set,
where would the information be kept during that month?
I'm looking
for a way to force the browser to set it in the same page containing
the JS statement that attempts to set it.


Not possible in my opinion, follows your wrong assumption.

=======================

Let's test it, however:
<script type='text/javascript'>

document.cookie="myName=Evertjan"

alert(document.cookie)

</script>

It seems I am right, Don,
it returns the cookie string the first time.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #4
Don
On 13 Feb 2005 15:05:49 GMT, "Evertjan." <ex**************@interxnl.net> wrote:
Don wrote on 13 feb 2005 in comp.lang.javascript:
That would mean that if your first page is loaded and then you trip
over the power cable, disconnecting the pc, the cookie would not be
set?

Seems very improbable to me.

My tests seem to verify what I've read, and that is that the browser
doesn't actually "set" the cookie until it encounters a subsequent
page requiring its use.


How did you test that, Don?
So, I suspose your theory that it wouldn't be
set it the pc lost power would be true.


Well I don't, offhand.
Putting that aside, and assuming the foregoing is true,


I would not assume that.
Please tell me what you mean by "set" in this case:
That the cooky file is placed in the IE temp structure?

What if that 'next page' is accessed a month later and the browser has
been closed down inbetween. Would you suggest that the cookie [one with
an expiry date, I mean, of course] is lost then?

That is contrary to my experience.

If it is not lost and not set,
where would the information be kept during that month?
I'm looking
for a way to force the browser to set it in the same page containing
the JS statement that attempts to set it.


Not possible in my opinion, follows your wrong assumption.

=======================

Let's test it, however:
<script type='text/javascript'>

document.cookie="myName=Evertjan"

alert(document.cookie)

</script>

It seems I am right, Don,
it returns the cookie string the first time.

Evertjan,

You're right. I just realized in my script I use a function to extract cookies, and I didn't
extract again after making a change. So, it didn't look like my change had taken effect. Can't
believe I missed that one. I must have misinterperted the passage about a cookie not being set
until the following page is read. I think what they probably meant was that it isn't set until the
next reference (which apparently can be in the same page).

Thanks for your help.
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 23 '05 #5
Lee
Don said:
You're right. I just realized in my script I use a function to extract cookies,
and I didn't
extract again after making a change. So, it didn't look like my change had
taken effect. Can't
believe I missed that one. I must have misinterperted the passage about a
cookie not being set
until the following page is read. I think what they probably meant was that it
isn't set until the
next reference (which apparently can be in the same page).


As far as the current page is concerned, the value is set immediately.
Your reference is probably saying that the server doesn't see the value until
the next time the page is requested.

Jul 23 '05 #6
Don
On 13 Feb 2005 12:23:03 -0800, Lee <RE**************@cox.net> wrote:
Don said:
You're right. I just realized in my script I use a function to extract cookies,
and I didn't
extract again after making a change. So, it didn't look like my change had
taken effect. Can't
believe I missed that one. I must have misinterperted the passage about a
cookie not being set
until the following page is read. I think what they probably meant was that it
isn't set until the
next reference (which apparently can be in the same page).


As far as the current page is concerned, the value is set immediately.
Your reference is probably saying that the server doesn't see the value until
the next time the page is requested.

Ok, that makes more sense to me. Thanks for your reply.
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 23 '05 #7
JRS: In article <Xn********************@194.109.133.29>, dated Sun, 13
Feb 2005 14:17:11, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Don wrote on 13 feb 2005 in comp.lang.javascript:
I understand that when I send


You mean "set" I hope?
a cookie in a client-side page
containing JS, it isn't actually "set" until the next page is loaded.
Is there some way to "set" it within the same html/JS page so it can
be accessed by other JS scripts in the same page?

That would mean that if your first page is loaded and then you trip over
the power cable, disconnecting the pc, the cookie would not be set?

Seems very improbable to me.


ISTM quite possible that a browser reads the cookie file into memory
when it starts, uses the memory file for read/write, and saves the
cookie file when it is closed down. Other programs seem to work that
way with "status" information. One could test it by playing with
cookies in a two-browser system, or by viewing the cookie file by a non-
browser method, or by something like the method you imply (pressing the
reset button seems kinder).

Or that it only writes the cookie file on page change.

But I don't know whether it does either of those in this case.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jul 23 '05 #8
Evertjan. wrote:

<--snip-->
Let's test it, however:
<script type='text/javascript'>

document.cookie="myName=Evertjan"

alert(document.cookie)

</script>
That doesn't mean a cookie was set, it means either a cookie was set or
a property of document named cookie was set to myName=Evertjan. Test:

<script type='text/javascript'>
document.chicken="myName=Evertjan"
alert(document.chicken)
</script>
It seems I am right, Don,
I disagree.
it returns the cookie string the first time.


No, it returns a property of document named cookie. It doesn't mean a
cookie was actually written, stored, or saved.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #9
Randy Webb wrote on 14 feb 2005 in comp.lang.javascript:
No, it returns a property of document named cookie. It doesn't mean a
cookie was actually written, stored, or saved.


That was why I repeatedly asked for a definition of "set".

Your above de facto definition of a cookie-with expiry date
is not my interpretation of "set" in the context of the OQ,
as all he wanted is to use the cookie content on the same page,
as I believe. Not in a dual browser setup.

That such cookies are not saved even if the browser is not closed when the
pc craches or looses power before that seems out of the question, but you
could proove that by testing in the way you suggested.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #10

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

Similar topics

6
by: aa | last post by:
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini in php.ini I have: SMTP = localhost SMTP_PORT = 25...
2
by: Dayne | last post by:
I know I can get the user's last input info with the win32 function "GetLastInputInfo", but how do I set this value without any physical input from the user? Any idea? DT
2
by: AA Arens | last post by:
When I place a record serch utility (vos the button placement wizzrd), I discovered that the Match setting is "Whole Field" by default. How to make "Any Part Of Field" default?
0
by: Torsten Sturm | last post by:
Hello, SP1 of Windows Server introduced a new "feature" in the GlobalizationConfig class called EnableBestFitResponseEncoding. Effect is that when you set anything other than UTF8 in...
2
by: Ken Schutte | last post by:
Lets say I want an integer class that lets you attach arbitrary attributes. I can simply do: class foo(int): pass x = foo(5) x.text = "okay" print x, x.text # prints "5 okay" So,...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: robert | last post by:
Why can the default locale not be set by its true name? but only by '' ? : PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32. (None, None) Traceback (most recent call last): File...
1
by: Kerem Gümrükcü | last post by:
Hi All, i am too tired now to find this out by my own, but why does my while loop "while(readline==Console.ReadLine())" needs twice return hit to read the line, after setting...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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,...
0
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...

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.