It seems I've found a Firefox bug in official build v2.0.0.1. This is really something, because I've never found any before (which is a miracle again since FF is known to be full of bugs).
It's in the JavaScript engine and involves properties of anchor JS objects.
Make a page with an anchor tag that has no
href
attribute and add some JS code that tries to enumerate the
hostname
property of the anchor objects ...
<html>
<body>
<a href="http://www.somesite.somewhere/">anchor #1</a>
<br>
<a>anchor #2</a>
<script type="text/javascript">
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
alert(i + ". anchor, hostname=" + anchors[i].hostname);
}
</script>
</body>
</html>
It will display the
hostname
property of the first anchor object properly, but it'll throw the following exception for the second one:
Error: uncaught exception: [Exception... "Component returned failure code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult: "0x804b000a (<unknown>)" location: "JS frame :: http://yourserver.yourdomain/example.html :: <TOP_LEVEL> :: line 9" data: no]
The correct behaviour would be to return "undefined" for the hostname property of the second anchor. The exception is raised even if we try to check for the existence of the
hostname
property through a call to
typeof
, eg.
if (typeof anchors[i].hostname != "undefined") { ... }
The bug is present in both the Windows and the Mac OS X build.
I've attached the example HTML file so you can test whether your version has the bug too. The exception is visible in the error console (available in the Tools menu).
Comments
it's in 1.5 too, but there's a fix
if (!typeof anchors[i].href.value) { ... }
Hope this helps.....
Re: it's in 1.5 too, but there's a fix
href
attribute of the anchors (nothref.value
) that one should look for. However thehostname
attribute is there to provide some convenience to the developer. Of course one can use thehref
attribute and dig out the hostname by himself (eg. with a regular expression), if one absolutely has to.One strange thing I've found is that looking at my example page with Firebug I can see all the attributes of the anchor object and Firebug does not complain about any problem with the second
anchor
(that has nohref
). Or maybe Firebug just silently swallows the error thrown by Firefox, when it tries to evaluate all the attributes of the anchor object?PS: btw. Firefox 2.0.0.12 (Linux version) still has the bug.
still there in 2.0.0.17
There is definitely no problem with my code & no other browser complains.
Just in case somebody else trips over this!
bug is fixed in Firefox 3.0.3