Loading ...
Sorry, an error occurred while loading the content.
 

Re: [JavaScript] Re: How do I do a substring operator on a document.location string

Expand Messages
  • Keith Maika
    ... Well, document.location isn t a string, that d be why. window.location is how you d reference the location object also. There is window.location, and
    Message 1 of 5 , Jan 31, 2003
      jstevebarber wrote:
      > --- In javascript_official@yahoogroups.com, "jstevebarber
      >
      > Figured it out, FINALLY ... you've got to use the .href operator.
      > For some reason the strings coming out fo document.location won't
      > subsequently work with a .substring, but the strings coming out of
      > document.location.href will.
      >
      > Thanks anyway
      >
      > SteveB
      >

      Well, document.location isn't a string, that'd be why. window.location
      is how you'd reference the location object also. There is
      window.location, and document.URL, but no document.location.



      window.location is an object representing the current location, broken
      down into various parts of the url (location.hash, location.hostname,
      location.href, location.protocol, ...). Here's a good little script to
      use if you want to see how an object is setup.

      function alertObj(obj){
      var str='';
      for (var i in obj){
      str+=i+':\t'+obj[i]+'\n';
      }
      alert(str);
      }
    • Wayne Fuller
      ... That would be because document.location returns an object while document.location.href returns a string. __________________________________________________
      Message 2 of 5 , Feb 3, 2003
        --- "jstevebarber <steve.barber@...>"
        <steve.barber@...> wrote:
        > --- In javascript_official@yahoogroups.com,
        > "jstevebarber
        >
        > Figured it out, FINALLY ... you've got to use the
        > .href operator.
        > For some reason the strings coming out fo
        > document.location won't
        > subsequently work with a .substring, but the strings
        > coming out of
        > document.location.href will.
        >
        > Thanks anyway
        >
        > SteveB
        >
        > snip
        >
        > >
        > > What I want to do is get the file name (without
        > the path) of the
        > > currently active html file. as in:
        > >
        > > pathfile = document.location
        > > file = pathfile.substring(7,8)
        > >
        > > where 7, of course, is the index of the starting
        > character of the
        > > file.
        > >
        >

        That would be because document.location returns an
        object while document.location.href returns a string.

        __________________________________________________
        Do you Yahoo!?
        Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
        http://mailplus.yahoo.com
      • davidblackledge
        First problem: document.location is deprecated... don t use it anymore... it conflicted with (and means the same thing as) window.location. Either use
        Message 3 of 5 , Feb 3, 2003
          First problem: document.location is deprecated... don't use it
          anymore... it conflicted with (and means the same thing as)
          window.location. Either use window.location or document.URL.
          document.URL is always a string, not an object.

          Second problem: Latest version of the Netscape DOM is documented as
          having window.location itself as a String, which means .href won't
          work anymore... so to be completely compatible do this:

          window.location.toString();

          If location is a string, .toString() just returns the same string...
          and for older versions .toString() of the location object is defined
          to give you the same result as .href

          David.

          --- In javascript_official@yahoogroups.com, Wayne Fuller
          <pacofuller@y...> wrote:
          >
          > --- "jstevebarber <steve.barber@e...>"
          > <steve.barber@e...> wrote:
          > > --- In javascript_official@yahoogroups.com,
          > > "jstevebarber
          > >
          > > Figured it out, FINALLY ... you've got to use the
          > > .href operator.
          > > For some reason the strings coming out fo
          > > document.location won't
          > > subsequently work with a .substring, but the strings
          > > coming out of
          > > document.location.href will.
          > >
          > > Thanks anyway
          > >
          > > SteveB
          > >
          > > snip
          > >
          > > >
          > > > What I want to do is get the file name (without
          > > the path) of the
          > > > currently active html file. as in:
          > > >
          > > > pathfile = document.location
          > > > file = pathfile.substring(7,8)
          > > >
          > > > where 7, of course, is the index of the starting
          > > character of the
          > > > file.
          > > >
          > >
          >
          > That would be because document.location returns an
          > object while document.location.href returns a string.
          >
          > __________________________________________________
          > Do you Yahoo!?
          > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
          > http://mailplus.yahoo.com
        Your message has been successfully submitted and would be delivered to recipients shortly.