contentWindow - portable alternative?

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

    contentWindow - portable alternative?

    i'm using the following construct to access form fields within an
    iframe:

    var x = document.getEle mentById('prefs _iframe').conte ntWindow.docume nt.forms["prefs_form "];

    works great in IE and Mozilla/Firefox. doesn't work in Safari. my
    DHTML reference book says that contentWindow is only supported in
    NN7/IE5.5(Win). what's the DOM-friendly approach to accessing form
    fields within an iframe?

    the book says to use contentDocument .defaultView but i get [null] when
    i try that.

    -jsd-
  • Richard Cornford

    #2
    Re: contentWindow - portable alternative?

    Jon Drukman wrote:[color=blue]
    > i'm using the following construct to access form fields within an
    > iframe:
    >
    > var x =
    >[/color]
    document.getEle mentById('prefs _iframe').conte ntWindow.docume nt.forms["pr
    efs_form"];[color=blue]
    >
    > works great in IE and Mozilla/Firefox. doesn't work in Safari. my
    > DHTML reference book says that contentWindow is only supported in
    > NN7/IE5.5(Win). what's the DOM-friendly approach to accessing form
    > fields within an iframe?[/color]

    The best cross-browser method is to access the IFRAME's global/window
    object as a member of the - frames - collection of its containing
    window/frame and go into the IFRAME document through its - document -
    property. That becomes slightly more cross-browser when you give the
    IRAME a name attribute in addition to an ID (They can, and probably
    should, be identical):-

    frames['prefs_iframe'].document.forms["prefs_form "];
    [color=blue]
    > the book says to use contentDocument .defaultView but i
    > get [null] when i try that.[/color]

    That really doesn't make much sense as - defaultView - is specified as
    an implementation of the - AbstractView - interface, and its -
    document - property will refer back to the same object as was referred
    to by - contentDocument - (making it a pointless side track).

    Richard.


    Comment

    • Jon Drukman

      #3
      Re: contentWindow - portable alternative?

      "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message news:<cbt01g$96 n$1$8302bc10@ne ws.demon.co.uk> ...[color=blue]
      > The best cross-browser method is to access the IFRAME's global/window
      > object as a member of the - frames - collection of its containing
      > window/frame and go into the IFRAME document through its - document -
      > property. That becomes slightly more cross-browser when you give the
      > IRAME a name attribute in addition to an ID (They can, and probably
      > should, be identical):-
      >
      > frames['prefs_iframe'].document.forms["prefs_form "];[/color]

      here's what i came up with through my own experimentation :

      var x = document.getEle mentById('prefs _iframe');

      if (x.contentWindo w) {
      x = x.contentWindow .document.forms["prefs_form "];
      }
      else {
      x = x.contentDocume nt.forms["prefs_form "];
      }

      works on IE, Moz & Safari. your version seems much more compact
      although not very DOM-centric.

      -jsd-

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: contentWindow - portable alternative?

        Jon Drukman wrote:[color=blue]
        > "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message news:<cbt01g$96 n$1$8302bc10@ne ws.demon.co.uk> ...[/color]

        Please do not write attribution novels. The name of the person which
        text is quoted is sufficient to follow the discussion. Anything else
        can be retrieved via the headers of the postings. Duplicating it
        renders discussions less legible.
        [color=blue][color=green]
        >> [...]
        >> frames['prefs_iframe'].document.forms["prefs_form "];[/color]
        >
        > here's what i came up with through my own experimentation :
        >
        > var x = document.getEle mentById('prefs _iframe');
        >
        > if (x.contentWindo w) {
        > x = x.contentWindow .document.forms["prefs_form "];
        > }
        > else {
        > x = x.contentDocume nt.forms["prefs_form "];
        > }
        >
        > works on IE, Moz & Safari. your version seems much more compact
        > although not very DOM-centric.[/color]

        Yes, it *seems* to be so. The `frames' collection is part of a
        widespread, yet not fully standardized DOM, called "DOM Level 0"
        which originates from NN/IE3+ and is still supported in current
        browsers (and upon which the W3C DOM is built) while the W3C DOM
        is not always fully supported. (Yes, there has been a DOM before
        the W3C DOM and there are still other DOMs!, namely the Gecko
        DOM). I wonder what you think "DOM-centric" would mean here.


        PointedEars

        Comment

        • Dr John Stockton

          #5
          Re: contentWindow - portable alternative?

          JRS: In article <40ED5195.70702 09@PointedEars. de>, seen in
          news:comp.lang. javascript, Thomas 'PointedEars' Lahn
          <PointedEars@nu rfuerspam.de> posted at Thu, 8 Jul 2004 15:52:21 :[color=blue]
          >Jon Drukman wrote:[color=green]
          >> "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message news:<cbt01g[/color]
          >$96n$1$8302bc1 0@news.demon.co .uk>...
          >
          >Please do not write attribution novels. The name of the person which
          >text is quoted is sufficient to follow the discussion. Anything else
          >can be retrieved via the headers of the postings. Duplicating it
          >renders discussions less legible.[/color]

          Ignore him. Current Internet draft standards encourage attribution
          details.

          The pointed one only wishes to allow that which he himself finds useful.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
          Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
          Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
          No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

          Comment

          Working...