Click to See Complete Forum and Search --> : Javascript 'Imageswap' function fails...
Kurylo
04-22-2002, 04:51 PM
I found a javascript resulting in a imageswap. The problem is: when a page contains more than one function calls (or how I should name them?), the imageswap function don't work.
And after that, can you answer one question: HOW TO MAKE THOSE IMAGES SWAP WHEN THERE ARE MORE THAN ONE CALLS TO ONE JAVASCRIPT FUNCTION?
I really need help. Any suggestions are welcome.
Kurylo
04-22-2002, 04:57 PM
Here are those html's:
1. WORKS ---------------------------------------------------------------------
<html>
<head>
<body onLoad="MM_preloadImages('image1-2.gif','image2-2')">
<script language="JavaScript">
function MM_swapImgRestore() {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() {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) {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); return x;}
function MM_swapImage() {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>
</head>
<TABLE border=1 bordercolor="#333333" style="border-collapse: collapse">
<TR>
<TD>
<a href="reference1.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but01','','image1-2.gif',1)">
<img name="but01" border="0" src="image1-1.gif" width="11" height="12" alt="AltText1"> reference1</a>
<a href="reference2.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but02','','image2-2.gif',1)">
<img name="but02" border="0" src="image2-1.gif" width="11" height="12" alt="AltText2"> reference2</a>
</TD>
</TR>
<TR><TD>Some Information Here</TD></TR>
</TABLE>
Kurylo
04-22-2002, 04:59 PM
Here are those html's:
1. FAILS ---------------------------------------------------------------------
<html>
<head>
<body onLoad="MM_preloadImages('image1-2.gif','image2-2')">
<script language="JavaScript">
function MM_swapImgRestore() {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() {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) {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); return x;}
function MM_swapImage() {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>
</head>
<TABLE border=1 bordercolor="#333333" style="border-collapse: collapse">
<TR>
<TD>
<a href="reference1.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but01','','image1-2.gif',1)">
<img name="but01" border="0" src="image1-1.gif" width="11" height="12" alt="AltText1"> reference1</a>
<a href="reference2.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but02','','image2-2.gif',1)">
<img name="but02" border="0" src="image2-1.gif" width="11" height="12" alt="AltText2"> reference2</a>
</TD>
</TR>
<TR><TD>Some Information Here</TD></TR>
<TR>
<TD>
<a href="reference1.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but01','','image1-2.gif',1)">
<img name="but01" border="0" src="image1-1.gif" width="11" height="12" alt="AltText1"> reference1</a>
<a href="reference2.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('but02','','image2-2.gif',1)">
<img name="but02" border="0" src="image2-1.gif" width="11" height="12" alt="AltText2"> reference2</a>
</TD>
</TR>
</TABLE>
Kurylo
04-22-2002, 05:01 PM
image1-1.gif, image1-2.gif, image2-1.gif and image2-2.gif are any graphic files.
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.