Re: Cookie question
- From: "Tom Cole" <tcole6@xxxxxxxxx>
- Date: 15 Sep 2006 10:19:07 -0700
DoomedLung wrote:
Hey, I recently bought "The Javascript and DHTML Cookbook" by Danny
Goodman.
I'm at Chapter 1, part 1.9 "Reading and Writing Strings for Cookies"
and was just interested in a utility function that grabs a cookie
value:
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
The part I don't understand is the if statement within the function,
why is it checking if endStr equals to false?
In case cookie returned no value from the supplied offset. It may also
work if there was no cookie at all or the cookie was empty (any experts
can chime in on that one).
Javascript has this neat ability (I say neat because java doesn't have
it) where null equals false. That little nuance makes a LOT of things
easier, especially when trying to do things like detect a browser's
capabilities or the presence (or lack thereof) of a DOM node.
For example, the statement
if (e.which) {
....
}
only executes if Javascript can evaluate the e.which object. That's
very cool in my eyes.
The book is kinda vague in explaining what this means! Any help would
be great.
Cheers
.
- Follow-Ups:
- Re: Cookie question
- From: DoomedLung
- Re: Cookie question
- References:
- Cookie question
- From: DoomedLung
- Cookie question
- Prev by Date: Re: put XML document in json
- Next by Date: Re: Cookie question
- Previous by thread: Cookie question
- Next by thread: Re: Cookie question
- Index(es):
Relevant Pages
|