| |
|
|
Programming and Scripts: Web Developers Forum
06-28-2005, 12:30 AM
|
#1
|
|
Super Moderator
Join Date: Mar 2005
Location: England
Posts: 182
|
Javascript issue
I'm having an issue with Javascript, it's an onmouseover script, it works in Firefox but not in IE. The code is below:
The Javascript code
Code:
<script="javascript">
<!-- Hide script from old browsers
if (document.images) {
loz = new Image
aol = new Image
alttp = new Image
la = new Image
oot = new Image
mm = new Image
ooa = new Image
oos = new Image
fs = new Image
ww = new Image
tmc = new Image
fsa = new Image
tp = new Image
off = new Image
loz.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/loz2.gif"
aol.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/aol2.gif"
alttp.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/alttp2.gif"
la.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/la2.gif"
oot.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/oot2.gif"
mm.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/mm2.gif"
ooa.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/ooa2.gif"
oos.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/oos2.gif"
fs.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/fs2.gif"
ww.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/ww2.gif"
tmc.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/tmc2.gif"
fsa.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/fsa2.gif"
tp.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/tp2.gif"
off.src = "<?php echo $mosConfig_live_site;?>/templates/sandydunes/gameheader.gif"
}
function chgImg(imgField,newImg) {
if (document.images) {
document[imgField].src= eval(newImg + ".src")
}
}
// End hiding script from old browsers -->
</script>
The image bit:
Code:
<img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/gameheader.gif" name="textField" alt=""><a href="/content/section/4/61/" onmouseover="chgImg('textField','loz')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/loz.gif" alt="" border="0" /></a><a href="/content/section/5/79/" onmouseover="chgImg('textField','aol')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/aol.gif" border="0" alt="" /></a><a href="/content/section/6/89/" onmouseover="chgImg('textField','alttp')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/alttp.gif" alt="" border="0" /></a><a href="/content/section/7/90/" onmouseover="chgImg('textField','la')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/la.gif" alt="" border="0" /></a><a href="/content/section/8/92/" onmouseover="chgImg('textField','oot')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/oot.gif" alt="" border="0" /></a><a href="/content/section/9/93/" onmouseover="chgImg('textField','mm')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/mm.gif" alt="" border="0" /></a><a href="/content/section/10/94/" onmouseover="chgImg('textField','ooa')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/ooa.gif" border="0" alt="" /></a><a href="/content/section/11/95/" onmouseover="chgImg('textField','oos')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/oos.gif" alt="" border="0" /></a><a href="/content/section/12/96/" onmouseover="chgImg('textField','fs')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/fs.gif" alt="" border="0" /></a><a href="/content/section/13/97/" onmouseover="chgImg('textField','ww')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/ww.gif" alt="" border="0" /><a href="/content/section/14/98/" onmouseover="chgImg('textField','tmc')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/tmc.gif" alt="" border="0" /><a href="/content/section/15/99/" onmouseover="chgImg('textField','fsa')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/fsa.gif" border="0" alt="" /></a><a href="/content/section/16/101/" onmouseover="chgImg('textField','tp')" onmouseout="chgImg('textField','off')"><img src="<?php echo $mosConfig_live_site;?>/templates/sandydunes/tp.gif" border="0" alt="" /></a>
Any help would really be appreciated.
Thanks in advance.
|
|
|
06-28-2005, 09:32 PM
|
#2
|
|
TalkWebDev Enthusiast
Join Date: Mar 2005
Posts: 37
|
Did you check my tutorial on images? There is a whole section on rollovers.
__________________
Sticky Icky
|
|
|
06-29-2005, 06:47 AM
|
#3
|
|
Prophet of 7ruth
Join Date: Mar 2005
Location: CT, USA
Posts: 41
|
Should work. Just edit the code to match your images. Tested and works in both Firefox and IE.
Goes in <head> tags:
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
Modified <body> tag: (this preloads the rollover images... make sure to edit it to match your images)
Code:
<body onLoad="MM_preloadImages('rolloverimage.jpg','ect.jpg')">
And your image code. Again, edit to match:
Code:
<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','rolloverimage.jpg',1)"><img src="baseimage.jpg" alt="rollover" name="Image1" border="0"></a>
Last edited by Captain Cornflake : 06-29-2005 at 06:53 AM.
|
|
|
07-10-2005, 05:06 PM
|
#4
|
|
Super Moderator
Join Date: Mar 2005
Location: England
Posts: 182
|
Thanks for the help! I'm fixing it as we speak  .
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 04:45 AM.
|
 |
 |
|
|