Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Stuck with external .js files

help needed


Andrew Thomas

7:10 pm on Oct 21, 2002 (gmt 0)

10+ Year Member

Ok, im trying to create a site where my content is at the top of the page. So ive used CSS and header and footer files.

The problem is, ive used Macromedia Dreameaver Rollover buttons, which are in the header.asp, i would like to put the <script> into an external .js file, but each time i seperate the code i get an error,

here is the code :-

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];}
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<td><img src="images/MainTopPanel.jpg" width="760" height="94" /></td>
<td><a href="index1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','images/nav%20buttons/Home%20Y.jpg',1)"><img src="images/nav%20buttons/Home%20W.jpg" alt="home" name="Image2" width="259" height="24" border="0" id="Image2" /></a><a href="biography.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','images/nav%20buttons/Biog%20Y.jpg',1)"><img src="images/nav%20buttons/Biog%20W.jpg" alt="biography" name="Image4" width="125" height="24" border="0"></a><a href="album.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','images/nav%20buttons/Album%20Y.jpg',1)"><img src="images/nav%20buttons/Album%20W.jpg" alt="albums" name="Image3" width="92" height="24" border="0"></a><a href="news.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','images/nav%20buttons/News%20Y.jpg',1)"><img src="images/nav%20buttons/News%20W.jpg" alt="news and gigs" name="Image5" width="128" height="24" border="0"></a><a href="contact.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image6','','images/nav%20buttons/Contact%20Y.jpg',1)"><img src="images/nav%20buttons/Contact%20W.jpg" alt="contacts" name="Image6" width="156" height="24" border="0"></a></td>

My body tags etc are in the main index.asp.

Can someone please explain if it is possable to seperate the above script code and place it into a .js file, ive tried but with no luck



7:24 pm on Oct 21, 2002 (gmt 0)

10+ Year Member

Put <script src="/rollover.js">
</script> in head and put everything between <script> and </script> (not those tags) in rollover.js


7:39 pm on Oct 21, 2002 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Yes, the <script> tags do not go in the js file.

Since we're on the subject of Macromedia rollovers, though, I would take about 10 minutes and ditch all that bloated code. Do a search here on the site for rollover buttons and you'll find a way to do the same thing in about 6 lines of code. If you don't find one, post again, and I'll post what I use. It's clean, easy to understand, and always works if the user has javascript.

Andrew Thomas

7:46 pm on Oct 21, 2002 (gmt 0)

10+ Year Member

thanks maccas its works great, i was doing everything you said apart from i was including the <script> </script> tags within the .js files, took these out and it works fine.

However txbakers, ive looked around for this shorter script and cannot find it :(

If you can point me in the right direction id be gratefull :)

Is this code browser compliant? if so id like to use it if its shorter, as i dont really understand what all this bloated code does anyway.

thankyou both



8:58 pm on Oct 21, 2002 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Here's a thread that might help you in your search for an economical rollover:
Bare-bones rollover [webmasterworld.com]

Featured Threads

Hot Threads This Week

Hot Threads This Month