homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Using javascript for "preload" and common borders
Help for a newbie

10+ Year Member

Msg#: 143 posted 6:59 pm on Jun 27, 2002 (gmt 0)

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.



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

Msg#: 143 posted 7:12 pm on Jun 27, 2002 (gmt 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.


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

Msg#: 143 posted 7:25 pm on Jun 27, 2002 (gmt 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. ;) )


10+ Year Member

Msg#: 143 posted 6:48 am on Jun 28, 2002 (gmt 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.


10+ Year Member

Msg#: 143 posted 4:28 pm on Jun 28, 2002 (gmt 0)

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! :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved