View Full Version : how to do external scripting?

09-08-2011, 12:59 PM
Dear Forum,

I have a website of quite a few pages which also has a style sheet switcher so the user can select their own customised graphics and layout (css file)

these css files load in the graphics but only when the call is clicked... even if the page has already been opened for seconds or minutes when the graphics could have been loaded in for an instant switch.

so i implemented the following code:

<SCRIPT language="javascript">

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];}}


<body onLoad="MM_preloadImages('/corporate/heading.png','/creative/heading.png','/earth/heading.png','/under-the-sea/heading.png','/space-and-stars/heading.png','/classical/heading.png','/corporate/document.jpg','/space-and-stars/document.png','/creative/document.jpg','/earth/background.jpg','/under-the-sea/background.jpg','/classical/document.png','/classical/background.jpg','/under-the-sea/document.png','/corporate/home-graphics.png','/earth/content.jpg','/earth/footer.jpg','/earth/home-graphics.png','/under-the-sea/home-graphics.png','/creative/home-graphics.png','/space-and-stars/background.jpg','');">

it works fantastically - you open the page and as long as it takes to notice where you can click the styles is the same amount of time it takes to have the styles cached for the styles switch immediately and effortlessly.

however, the site has grown and is now quite a number of pages with the above in each html file. ive just added a "creative 2" style, which has caused the above to need updating........ the maintenance of this code is inefficient to edit each page.

would someone be able to point or show me how to, in principle:

<body onLoad="MM_preloadImages('/styles-code.js);">

styles-code.js?? page:




and have 1 page of this code called in by all pages in an easy to see and edit list?

would really appreciate guidance with this,

09-08-2011, 02:25 PM
Put this in the HEAD section of all your files:

<script type="text/javascript" src="styles-code.js"></script>

And write you JS code in that file. Only the code, without the tags <script> and </script>

See also:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum