Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Using javascript for "preload" and common borders

Help for a newbie



6:59 pm on Jun 27, 2002 (gmt 0)

Inactive Member
Account Expired


Hello, I'm new to all this and was just reading through a thread that talked about using Javascript to "preload" images that aren't on the index page while the user is reading the index page.. Have only used Java for the "no right click". Am interested in the "preload". Does anybody know about this and if so would you mind giving an example of the code to use?
Another question if some of you don't mind, how can I use Javascript to call in a consistent bottom border (with all my navigation, copyright info, etc.) on my pages without having to code them all individually? I know it can be done but not being very familiar with javascript I don't know how.

Thanks so much.

7:12 pm on June 27, 2002 (gmt 0)


WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
votes: 0

Welcome Fitch,

I was wondering when you were going to get your question posted.


there are a lot of different ways to do this I am sure but here is what I use, people will inevitably have better solutions but I have used this for a couple of years now and it has served me well. I just do it straight up in the head, I don't call a function onload or anything like that.

var canUseImageArray = false;

if (document.images){
canUseImageArray = true;
if (canUseImageArray) {

menu1_on = new Image();
menu1_on.src = "/images/img1-on.gif";

menu1_off = new Image();
menu1_off.src = "/images/img1-off.gif";

menu2_on = new Image();
menu2_on.src = "/images/img2-on.gif";

menu2_off = new Image();
menu2_off.src = "/images/img2-off.gif";

then a function like this for the rolls

function rollmeover(pic,state) {
if (state == "on") {
document.images[pic].src = eval(pic + "_on.src");
} else if (state == "off") {
document.images[pic].src = eval(pic + "_off.src");

As for including common footers with javascript, I have never done that and I am not totally sure you can. I use php for that purpose.

7:25 pm on June 27, 2002 (gmt 0)

Senior Member

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

joined:Dec 6, 2000
votes: 0

Personally, I would think site-wide footers might be better done with server side includes... (assuming your host allows that)

You create the footer as a stand-alone file, and then insert a line in your page code where you want the footer to appear:

<!--#include file="footer.html" -->

(make sure the footer.html file is in the same directory as the pages you want it to appear on)

Most hosts will require pages that use server side includes (SSI) to use the extension ".shtml" but (This won't work on Windows hosting), you can often get around that by creating a file called ".htaccess" (saved as a plain text file with a plain text program like notepad), that has the following line in it:

AddHandler server-parsed .html .htm .shtml

If your host's server is configured to allow that trick, you can keep the regular .htm or .html extensions on your pages, and still use SSI calls for your footer file.

(There are a lot of other really cool things you can do with your .htaccess file, but that's all you need to know for SSI in a plain .html file. ;) )

6:48 am on June 28, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:June 7, 2002
votes: 0

if (document.images){...}

There's a problem with that. In many browsers, this test simply doesn't work -- I think because the document.images array is only available once all the images have downloaded and been rendered. One of the surest signs of a Macromedia rollover script is that it fails to preload the images. I've tried using onload, which ought to work -- but it doesn't.


4:28 pm on June 28, 2002 (gmt 0)

Inactive Member
Account Expired


Thank you, jatar_k, mivox and rewboss, for your responses and advice. I'll play around with what you've shared with me and see if I understand it. I might be back! :-)