document.links["id"].href -> Browsersafe?

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

    document.links["id"].href -> Browsersafe?

    Does this work in most browsers, namely MSIE?

    document.links["idOfTheElement "].href

    or does it have to be

    document.links[0].href

    ?

    Thanks and cheers,
    Konrad


  • Grant Wagner

    #2
    Re: document.links["id&quo t;].href -> Browsersafe?

    Konrad Mathieu wrote:
    [color=blue]
    > Does this work in most browsers, namely MSIE?
    >
    > document.links["idOfTheElement "].href
    >
    > or does it have to be
    >
    > document.links[0].href
    >
    > ?
    >
    > Thanks and cheers,
    > Konrad[/color]

    Why not try it?

    <body onload="alert(d ocument.links['test'].href);">
    <a href="test.html " id="test">A Link</a>

    The above works in Mozilla 1.5a, not IE

    <body onload="alert(d ocument.links(' test').href);">
    <a href="test.html " id="test">A Link</a>

    The above works in IE, not Mozilla 1.5a

    <body onload="alert(d ocument.getElem entById('test') .href);">
    <a href="test.html " id="test">A Link</a>

    The above works in IE 6SP1, Mozilla 1.5a and Opera 7.11. I didn't check
    the first two test in Opera because each failed in at least one of the
    two major browsers you probably want to support. Also, simply because I
    provided specific browser versions does not mean it won't work in early
    versions, it simply means those are the versions I tested the code with.

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Greg

      #3
      Re: document.links[&quot;id&quo t;].href -&gt; Browsersafe?

      "Konrad Mathieu" <nospam@nospam. com> wrote in message news:<105855039 9.30622.0@doris .uk.clara.net>. ..[color=blue]
      > thanks!
      >
      > "Grant Wagner" <gwagner@agrico reunited.com> schrieb im Newsbeitrag
      > news:3F1713E8.B 1DE3420@agricor eunited.com...[color=green]
      > > Konrad Mathieu wrote:
      > >[color=darkred]
      > > > Does this work in most browsers, namely MSIE?
      > > >
      > > > document.links["idOfTheElement "].href
      > > >
      > > > or does it have to be
      > > >
      > > > document.links[0].href
      > > >
      > > > ?
      > > >
      > > > Thanks and cheers,
      > > > Konrad[/color][/color][/color]

      The links collection seems to support the item method in both IE 6 and Netscape 7:

      <a href="a.htm" id='a1' name='anchor1'
      onclick="alert( document.links. item('a1').name ); return false;"[color=blue]
      >Anchor Name</a>[/color]

      Not an expert. FWIW.

      [color=blue][color=green]
      > >
      > > Why not try it?
      > >
      > > <body onload="alert(d ocument.links['test'].href);">
      > > <a href="test.html " id="test">A Link</a>
      > >
      > > The above works in Mozilla 1.5a, not IE
      > >
      > > <body onload="alert(d ocument.links(' test').href);">
      > > <a href="test.html " id="test">A Link</a>
      > >
      > > The above works in IE, not Mozilla 1.5a
      > >
      > > <body onload="alert(d ocument.getElem entById('test') .href);">
      > > <a href="test.html " id="test">A Link</a>
      > >
      > > The above works in IE 6SP1, Mozilla 1.5a and Opera 7.11. I didn't check
      > > the first two test in Opera because each failed in at least one of the
      > > two major browsers you probably want to support. Also, simply because I
      > > provided specific browser versions does not mean it won't work in early
      > > versions, it simply means those are the versions I tested the code with.
      > >
      > > --
      > > | Grant Wagner <gwagner@agrico reunited.com>
      > >
      > > * Client-side Javascript and Netscape 4 DOM Reference available at:
      > > *
      > >[/color]
      > http://devedge.netscape.com/library/...3/reference/fr
      > ames.html[color=green]
      > >
      > > * Internet Explorer DOM Reference available at:
      > > *
      > >[/color]
      > http://msdn.microsoft.com/workshop/a...l_reference_en
      > try.asp[color=green]
      > >
      > > * Netscape 6/7 DOM Reference available at:
      > > * http://www.mozilla.org/docs/dom/domref/
      > > * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
      > > * http://www.mozilla.org/docs/web-deve...upgrade_2.html
      > >
      > >[/color][/color]

      Comment

      Working...