Can someone please break this down to me...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Vasquez

    Can someone please break this down to me...


    var _section = location.search ? location.search .split("?")[1] : "latest"

    What does this line of code set ? Here is the code from which it came
    from...



    var _section = location.search ? location.search .split("?")[1] : "latest"
    var _date = new Date();
    if (location.href. indexOf("http://") >= 0)
    var _src =
    "http://www.geocities.c om/qzmicro/photolog/archives/"+_section+".js ?"+_date.
    getDay()
    else
    _src = "http://www.geocities.c om/qzmicro/photolog/archives/latest.js"

    document.write( "<SCRIPT src='"+_src+"'> <\/SCRIPT>")



    Thanks guys... 'Prechiate it.


  • Lee

    #2
    Re: Can someone please break this down to me...

    Tony Vasquez said:[color=blue]
    >
    >
    > var _section = location.search ? location.search .split("?")[1] : "latest"
    >
    >What does this line of code set ? Here is the code from which it came
    >from...[/color]

    var a = b ? c : d;

    means: if (b) evaluates to true, then a=c, otherwise, a=d.

    In your specific case, if the URL of this page contains
    anything after a question mark, then assign that string
    to _section, otherwise, assign "latest" to _section.

    Comment

    • Laurent Bugnion, GalaSoft

      #3
      Re: Can someone please break this down to me...

      Hi,

      Tony Vasquez wrote:[color=blue]
      > Understood, then what does location.search do? If it's not too much
      > trouble... thanks in advance.
      >
      > Tony[/color]

      "window.locatio n", which can also be written "location" alone (the
      window object is implicit) is an instance of the Location object, which
      has different properties. These properties are described here:

      <URL:
      http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/location.html>

      The "search" property is a string which contains the query string, in
      other words what comes after a '?' in an URL.

      Typically the query string is used server-side to build a page based on
      some parameters. It is also accessible to client-side scripts however,
      and can be used to pass parameters between one page and the other.

      One thing which must be noticed is that "location.searc h" contains the
      '?' after which the query string starts. I am unaware of the reasons
      behind this point of design, which is IMHO unnecessary and forces you to
      remove the '?' in your script, either with
      location.search .substring( 1 );
      or, like in your example
      location.search .split( '?' )[1];

      HTH,

      Laurent
      --
      Laurent Bugnion, GalaSoft
      Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
      Private/Malaysia: http://mypage.bluewin.ch/lbugnion
      Support children in Calcutta: http://www.calcutta-espoir.ch

      Comment

      • Tony Vasquez

        #4
        Re: Can someone please break this down to me...

        I love this place. Thanks, I understand now, and figured it was server
        side, because of the ? after the file extension on the URL. This clarifies
        a lot, ... :) I can now finish this script. See ya around.

        Tony Vasquez



        "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
        message news:bihhqp$d2r $1@rex.ip-plus.net...[color=blue]
        > Hi,
        >
        > Tony Vasquez wrote:[color=green]
        > > Understood, then what does location.search do? If it's not too much
        > > trouble... thanks in advance.
        > >
        > > Tony[/color]
        >
        > "window.locatio n", which can also be written "location" alone (the
        > window object is implicit) is an instance of the Location object, which
        > has different properties. These properties are described here:
        >
        > <URL:
        >[/color]
        http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/location.html>[color=blue]
        >
        > The "search" property is a string which contains the query string, in
        > other words what comes after a '?' in an URL.
        >
        > Typically the query string is used server-side to build a page based on
        > some parameters. It is also accessible to client-side scripts however,
        > and can be used to pass parameters between one page and the other.
        >
        > One thing which must be noticed is that "location.searc h" contains the
        > '?' after which the query string starts. I am unaware of the reasons
        > behind this point of design, which is IMHO unnecessary and forces you to
        > remove the '?' in your script, either with
        > location.search .substring( 1 );
        > or, like in your example
        > location.search .split( '?' )[1];
        >
        > HTH,
        >
        > Laurent
        > --
        > Laurent Bugnion, GalaSoft
        > Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
        > Private/Malaysia: http://mypage.bluewin.ch/lbugnion
        > Support children in Calcutta: http://www.calcutta-espoir.ch
        >[/color]


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Can someone please break this down to me...

          "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> writes:
          [color=blue]
          > "window.locatio n", which can also be written "location" alone (the
          > window object is implicit)[/color]

          Just to be pedantic (beginners can ignore this):

          The "window" is not implicit in the sense that it is automatically
          added if you omit it (what I read into "implicit") .

          The global object has a property called "location". As such, it can be
          used as a global variable. It is a reference to a Location object.

          The global object also has a property called "window". It too can be
          used as a global variable. The window property is a reference to the
          global object itself (just like "self", and possibly "top" and "parent").

          That means that you can access properties of the global object through
          the windows variable. Writing "window.locatio n" gives the same result
          as writing "location", it just takes one more step to find it:
          location : global object -> location property
          window.location : global object -> window property -> location property
          == global object

          Apart from my tendency to nitpick, what you said was fine.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          Working...