Zeb
February 2nd, 2005, 09:39 PM
I have a webpage which when a user puts the mouse over a picture it changes to something else, then back again - used for pretty buttons. Pretty standard.
It works perfectly in IE6, but I when I try testing it in Firefox, it doesn't work and the JavaScript console tells me "event is not defined". Now, I did some searching, and it appears that Firefox follows the DOM specification to the letter, while IE doesn't, and used some things that were in a draft version but not in the release version of the DOM spec. The weird thing is, I got the code for this from w3schools, which is done by w3 org which is the ones who (I thought) created DOM!
anyway, here is the code (relevant sections only):
<script language="javascript">
function highlight()
{
var sentence=event.srcElement.src
event.srcElement.src=sentence.substring(0, sentence.indexOf(".jpg")) + "sel.jpg"
}
function regular()
{
var sentence=event.srcElement.src
event.srcElement.src=sentence.substring(0, sentence.indexOf("sel.jpg")) + ".jpg"
}
</script>
..
..
..
<a href="home.htm" onmouseover="highlight()" onmouseout="regular()"><img src="img/home.jpg" border="0"></a>
Basically on mouseover I tell it to use the same jpg but with "sel" at the end of the name and then swap it back on mouseout.
how do i do this and support both IE and Firefox?
It works perfectly in IE6, but I when I try testing it in Firefox, it doesn't work and the JavaScript console tells me "event is not defined". Now, I did some searching, and it appears that Firefox follows the DOM specification to the letter, while IE doesn't, and used some things that were in a draft version but not in the release version of the DOM spec. The weird thing is, I got the code for this from w3schools, which is done by w3 org which is the ones who (I thought) created DOM!
anyway, here is the code (relevant sections only):
<script language="javascript">
function highlight()
{
var sentence=event.srcElement.src
event.srcElement.src=sentence.substring(0, sentence.indexOf(".jpg")) + "sel.jpg"
}
function regular()
{
var sentence=event.srcElement.src
event.srcElement.src=sentence.substring(0, sentence.indexOf("sel.jpg")) + ".jpg"
}
</script>
..
..
..
<a href="home.htm" onmouseover="highlight()" onmouseout="regular()"><img src="img/home.jpg" border="0"></a>
Basically on mouseover I tell it to use the same jpg but with "sel" at the end of the name and then swap it back on mouseout.
how do i do this and support both IE and Firefox?