...

View Full Version : image replacer for firefox?



tpeck
10-24-2005, 11:01 AM
Hi, I have a fairly ordinary image rollover script that (guess?) doesn't work in Firefox.

Can someone tell me why and suggest a good cross-browser replacement?

Many thanks,

Terry

*********************
<!--
var base= images/mo_"
var nrm = new Array();
var omo = new Array();
var stuff = new Array('image1','image2','image3');

// Pre-load part.

if (document.images)
{
for (i=0;i<stuff.length;i++)
{
nrm[i] = new Image;
nrm[i].src = base + stuff[i] + ".gif"
omo[i] = new Image;
omo[i].src = base + stuff[i] + "_omo.gif";
}
}


// The functions: first mouseover, then mouseout

function over(no)
{
if (document.images)
{
document.images[stuff[no]].src = omo[no].src
}
}

function out(no)
{
if (document.images)
{
document.images[stuff[no]].src = nrm[no].src
}
}
// End -->

**********************************

In the page I use:

<a onmouseover="over(0)" onmouseout="out(0)" href="http://www.whatever.com">
<img src="images/mo_image1.gif" name="image1" border="0" alt="" width="50" height="50" align="right"></a>

Image names are 'mo_image1.gif' and 'mo_image1_omo.gif'

mo = mouse over and omo = on mouse out.

Kor
10-24-2005, 12:52 PM
<script type="text/javascript">
var ini ='images/';
var mid ='_omo'
var fin ='.gif';
function roll(obj){
var oSrc = obj.getAttribute('src').split('/')[obj.getAttribute('src').split('/').length-1].split('.')[0]
obj.setAttribute('src',ini+oSrc+mid+fin);
obj.onmouseout=function(){
obj.setAttribute('src',ini+oSrc+fin)
}
}
</script>
...
...
<a href="http://www.whatever.com">
<img src="images/mo_image1.gif" border="0" alt="" width="50" height="50" align="right" onmouseover=roll(this)></a>

<a href="http://www.whatever.com">
<img src="images/mo_image2.gif" border="0" alt="" width="50" height="50" align="right" onmouseover=roll(this)></a>

<a href="http://www.whatever.com">
<img src="images/mo_image3.gif" border="0" alt="" width="50" height="50" align="right" onmouseover=roll(this)></a>

tpeck
10-24-2005, 01:32 PM
Thanks KOR. It's funky and neat BUT...

I applied your script and it works perfectly in IE, but not in Firefox.

I have uploaded a demo page at:

http://aapress.com.au/mouseoverdemo.html

...in case I have made an obvious error.

Is it really a crossover script?

Kor
10-24-2005, 02:08 PM
it works in Firefox... Check whether you have javascript disabled or not

tpeck
10-24-2005, 02:25 PM
Yup! It's all true. Javasacript was disabled! Oh dear...

Actually, my original works too, but yours is much better.

Thanks,

Terry



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum