Forum Moderators: open

Message Too Old, No Replies

Internet explorer error due to external jscript?

Good in Firefox

         

silverbytes

8:37 am on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When my page loads in bottom bar of Internet Explorer a yellow triangle appears (error in page)
line 13
car 2
Error: document.getElementByld(...) is null or not an object
Code: 0

Firefox doesnt complain

line 13 in my html page is this:

<link href="estilos.css" rel="stylesheet" type="text/css">

and line before that is:

<Script name="Lvl_ExtJS1" Language="Javascript" src="hoteles-scripts/js.js"></script>

in external js.js file


<!--//--><![CDATA[//><!--

sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]>

Im not sure but I think that code is not being used anymore. Is that the cause or can I modify something there to stop the IE error complain?

Bernard Marx

12:05 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there an element with id="nav" in the document?
(Sounds like there isn't)

Firefox may still be complaining, but quietly inside the Javascript console.

silverbytes

6:01 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No there is not (that element is on most of pages on site but not in that)
Can I add the parameter id="nav" to any element in code to quiet that?

Bernard Marx

6:12 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. I reckon patching with dummy elements is likely cause trouble in the future, and besides, it won't work here anyway.

Get defensive in the script:

Replace this:

var sfEls = document.getElementById("nav").getElementsByTagName("LI");

with this:

var sfEls = document.getElementById("nav");
if(!sfEls) return;
sfEls = sfEls.getElementsByTagName("LI");

silverbytes

12:26 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! Works ok!