split() one document.frames not allowed

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

    #1

    split() one document.frames not allowed

    Hi,

    I want to split the result from
    window.frames['data_frame'].document.locat ion;, this in order to find
    out which page is currently opened in the specific frame. When I do it
    like this:
    var source = window.frames['data_frame'].document.locat ion;
    // var source = "W3Schools is great!";

    index_source = source.split('/');


    IE gives an error that this method or property is not supported by this
    object. When I check it on the other var it is accepted. Is there any
    way I can make this work? I already tried to do it with
    document.getEle mentById().src etc.. but that is not very reliable.

    Thanks in advance, Maarten



  • Lee

    #2
    Re: split() one document.frames not allowed

    Muffinman said:[color=blue]
    >
    >Hi,
    >
    >I want to split the result from
    >window.frame s['data_frame'].document.locat ion;, this in order to find
    >out which page is currently opened in the specific frame. When I do it
    >like this:
    > var source = window.frames['data_frame'].document.locat ion;
    > // var source = "W3Schools is great!";
    >
    > index_source = source.split('/');
    >
    >
    >IE gives an error that this method or property is not supported by this
    >object.[/color]

    The location attribute of a document is not a string (it's a Location object),
    and so doesn't have a split() method. I believe the href attribute of Location
    is a string, so:

    window.frames['data_frame'].document.locat ion.href.split( '/');

    should work.

    Comment

    • RobB

      #3
      Re: split() one document.frames not allowed

      Lee wrote:[color=blue]
      > Muffinman said:[color=green]
      > >
      > >Hi,
      > >
      > >I want to split the result from
      > >window.frame s['data_frame'].document.locat ion;, this in order to[/color][/color]
      find[color=blue][color=green]
      > >out which page is currently opened in the specific frame. When I do[/color][/color]
      it[color=blue][color=green]
      > >like this:
      > > var source = window.frames['data_frame'].document.locat ion;
      > > // var source = "W3Schools is great!";
      > >
      > > index_source = source.split('/');
      > >
      > >
      > >IE gives an error that this method or property is not supported by[/color][/color]
      this[color=blue][color=green]
      > >object.[/color]
      >
      > The location attribute of a document is not a string (it's a Location[/color]
      object),[color=blue]
      > and so doesn't have a split() method. I believe the href attribute[/color]
      of Location[color=blue]
      > is a string, so:
      >
      > window.frames['data_frame'].document.locat ion.href.split( '/');
      >
      > should work.[/color]

      document.locati on has been deprecated for years, replaced by
      document.URL (read-only by spec, read/write in - you guessed it). A
      window's Location object is found at window.location , although it
      appears that virtually all browsers now map document.locati on to
      window.location , possibly to avoid errors. Because of the importance of
      [window.]location it can be read directly as a string, or replaced with
      a string. Of course, it isn't a string, and one thing you can't get
      away with, as Lee noted, is to invoke String object methods on it.
      Could do this:

      function getURL(doc)
      {
      var m = null;
      if (m = doc.URL.match(/[^\/\\]+$/))
      return m[0];
      return '';
      }

      alert(getURL(fr ames.data_frame .document));

      Comment

      Working...