about document.image1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hantechs@gmail.com

    about document.image1

    Hi, all

    I found I can get the img element named with "image1" in a html by
    using "document.image 1" with javascript. It's very convenient because
    I don't need to use the long method like getElementByNam e etc. I
    wonder if this approach is the part of the DOM? I have checked the DOM
    specification, but found nothing. Can somebody give me clue? Thanks.

    Regards.
  • Evertjan.

    #2
    Re: about document.image1

    hantechs@gmail. com wrote on 07 nov 2008 in comp.lang.javas cript:
    I found I can get the img element named with "image1" in a html by
    using "document.image 1" with javascript. It's very convenient because
    I don't need to use the long method like getElementByNam e etc. I
    wonder if this approach is the part of the DOM? I have checked the DOM
    specification, but found nothing. Can somebody give me clue? Thanks.
    This is one of the crazy "features" of IE,
    not cross-browser safe,
    and ever a source of errors in IE itself.

    Do not use it on open webpages.

    Names are not unique in HTML, IDs are.
    It is quite legal to give multiple images the same name.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: about document.image1

      hantechs@gmail. com wrote:
      I found I can get the img element named with "image1" in a html by
      using "document.image 1" with javascript. It's very convenient because
      I don't need to use the long method like getElementByNam e etc. I
      wonder if this approach is the part of the DOM?
      It must be part of a DOM, otherwise it would not work. You should be asking
      instead whether it is sanctioned by a Web standard. No, it is not. But see
      below.
      I have checked the DOM specification, but found nothing. Can somebody
      give me clue? Thanks.
      Read the ECMAScript Language Binding section of the W3C DOM Level 2 HTML
      Specification on "objects that implement the HTMLDocument interface" and on
      "objects that implement the HTMLCollection interface" to see that

      document.images["image1"]

      would be standards-compliant. It is also backwards-compatible because the
      earliest implementations , that of NN 3.0 and IE 3.0 (the so-called "DOM
      Level 0"), already supported it.


      PointedEars
      --
      var bugRiddenCrashP ronePieceOfJunk = (
      navigator.userA gent.indexOf('M SIE 5') != -1
      && navigator.userA gent.indexOf('M ac') != -1
      ) // Plone, register_functi on.js:16

      Comment

      • SAM

        #4
        Re: about document.image1

        Le 11/7/08 7:44 AM, hantechs@gmail. com a écrit :
        Hi, all
        >
        I found I can get the img element named with "image1" in a html by
        using "document.image 1" with javascript.
        It's the old way to get elements, and here : image

        But the element must have a 'name' and not only an 'id'.
        Take care if you have only ids that only IE will run with this feature.

        <img name="image1" id="image1" src blah >

        When a browser reads an html file its javascript engine parses the code,
        building all the JS trees (the old ones and the DOM).

        JS trees :
        - document.images
        - document.forms (and for each form : document.forms[i].elements)
        - document.anchor s
        - document.links
        - ...
        It's very convenient because
        I don't need to use the long method like getElementByNam e etc.
        usually you have to do :

        document.images['image1']
        this approach is the part of the DOM?
        Absolutely not ! the DOM is the DOM.
        You get or set elements via the Document Model Objects

        I think javascript DOM functions have been added with version 1.5

        I have checked the DOM specification, but found nothing.
        Of course :
        most of the time it is forbidden to give a 'name' to the elements,
        so the DOM doesn't know 'name', or almost not
        document.getEle mentsByName('aN ame');
        will return the collection of elements named 'aName'.
        Can somebody give me clue? Thanks.
        search about JavaScript 1.2

        --
        sm

        Comment

        Working...