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

K

Konrad Mathieu

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
 
G

Grant Wagner

Konrad said:
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

Why not try it?

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

The above works in Mozilla 1.5a, not IE

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

The above works in IE, not Mozilla 1.5a

<body onload="alert(document.getElementById('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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* 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-developer/upgrade_2.html
 
G

Greg

Konrad Mathieu said:
thanks!

Grant Wagner said:
Konrad said:
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

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;"
Anchor Name</a>

Not an expert. FWIW.

Why not try it?

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

The above works in Mozilla 1.5a, not IE

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

The above works in IE, not Mozilla 1.5a

<body onload="alert(document.getElementById('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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/fr
ames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_en
try.asp

* 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-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top