PDA

View Full Version : Is this an IE6-Bug?


Linuxhippy
03-21-2005, 01:42 PM
Hello!

I have the following problem: I want to set the background-attribute of an div-element via javascript and this works well for all browsers I tested except: IE6.
I found out that the event-method is never called, but I do not find my mistake :-(
If I replace the the setActive-call with "alert('Hello!');" everything works fine. I am quite confused...

Please help...

Thank you in advamce, lg Clemens


Here's the code:

<script type="text/javascript">
<!--
function setActive(elementName, active)
{
alert("Hallo!");
var element = document.getElementById(elementName);

if(active)
{
element.style.backgroundImage = "url(images/img_base.png)";
}else
{
element.style.backgroundImage = "url(images/black.png)";
}
}
-->
</script>

.............
somewhere later in body:

<div id="div1"
onMouseOver="setActive('div1', true);"
onMouseOut="setActive('div1', false);"
style="background-image:url(images/black.png); background-repeat:repeat-y; background-color:#000000;">
<P ALIGN="CENTER" style="margin:0px;">
<a HREF="topangebote%20maerz.htm" TARGET="_blank"> some text
</a>
</P>
</div>

coothead
03-21-2005, 03:18 PM
Hi there Linuxhippy,

and a warm welcome to these forums. :)

The problem for IE is setActive. :supereek:
Replace it with something else as it is an IE function name.

Also your function is unnecessarily complicated.
Try it like this...
<script type="text/javascript">
<!--
function swap(el) {

el.style.backgroundImage = "url(images/img_base.png)";

el.onmouseout=function() {

el.style.backgroundImage ="url(images/black.png)";
}
}
//-->
</script>

<div id="div1" onmouseover="swap(this)" style="background-image:url(images/black.png);background-repeat:repeat-y; background-color:#000000;"></div>

Linuxhippy
03-21-2005, 05:03 PM
Thanks a lot for your help - I did not know that so I think it would have took me ages to figure that out ;-)

Another interresting fact is, that the whole page looked well under a lot of different browsers (mozilla, konqueror, opera) but IE5/6 causes a lot of quirks and was the only browser which caused (beside this setActive stuff) major problems when rendering my page...

Thanks a lot again, you've really helped me a lot!

lg Clemens

coothead
03-21-2005, 05:46 PM
Hi there Linuxhippy,

If you are experiencing CSS code rendering problems in IE,
it is worth remembering that the use of a DOCTYPE is essential.
Without one IE renders the code in quirks mode :supereek: