[Javascript] Reading a variable from the URL

diego nunes dnunes at gmail.com
Tue Jul 17 18:10:39 CDT 2007


On 7/17/07, Terry Riegel <riegel at clearimageonline.com> wrote:
> I don't understand why this code produces the part of the URL after the ?
> mark. Can you please explain why it works? Also What does the {} mean?

    Hey, Terry.

    The {} is a way of creating a new Object (just like doing "var
something=new Object();"). Just to note: if you want to create an
Array, you can use "[]" as well as "new Array()" (like this: "var
myarray=[];").

    The "search" property of the "location" object (accessed through
"window.location.search") contains the "?" and everything after that
in a URL (or empty, in the case that the request doesn't contain any
parameter in the URL). By doing ".substring(1)", he is removing the
"?" from the string and getting only the wanted data. After that you
can just parse it as you prefer.

  Amplexos.

--
diego nunes
dnunes.com



More information about the Javascript mailing list