Re: Cookie question




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

.



Relevant Pages

  • Re: Getting the referer info into a form field?
    ... conditionally stored the referer in a Cookie, only if the referer was not ... and if the Cookie did not exist already (which would ... JavaScript alone, though, nice thinking - yes, a Cookie would be the way to ... >> Kevin Spencer ...
    (microsoft.public.frontpage.programming)
  • Re: [Full-disclosure] Google / GMail bug, all accounts vulnerable
    ... JavaScript code was being loaded. ... This would work if the session cookie is restricted to ... then google did two things. ... GMail account, but has nothing to do with CAPTCHAs. ...
    (Full-Disclosure)
  • PageLoad when BACK is clicked
    ... Basically I think you could do this by JavaScript. ... And then also create a cookie with a timestamp (and set it ... Retrieve the hidden form field value (into a var ... Otherwise reload the page. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Mozilla cookie stealing - Sandblad advisory #9
    ... Steal/spoof arbitrary cookie in Mozilla ... using the javascript URL. ... Parsing of host and path will stop when a space is found. ...
    (Bugtraq)
  • RE: HTTPModule - an interceptor indeed, but without communication skills!
    ... httpModule to check in the certain event before request has been processed ... easily manually append such querystring to bypass the validation. ... My suggestion is what about the cookie? ... In the validation code, you can use javascript ...
    (microsoft.public.dotnet.framework.aspnet)