Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

use onLoad to hide/show images

Posted on 2001-08-06
Last Modified: 2008-03-04

I have an intranet site with GIF images which load slowly and at different rates.  I am looking for someone who can give me usable code which preloads images into cashe (possibly using the onLoad function and looping until every image is loaded and then displaying the images all at once.)  

I use the <DIV> tag to position my images and can set my images to be hidden by default instead of visible.   I am a novice web developer with no javascript experience so please keep everything simple.

Thank you!

Question by:stevenshl
LVL 22

Expert Comment

ID: 6356011
Is it an IE only intranet?

If so you can use the following.

Add this to the <head>-section:
<style type='text/css'>

Then load the usual way (no changes needed in your current code). And then add the folowing script (also in the Head-section):
function document_onload()
   for(i=0;i<document.images.length;i++) document.images[i].style.visibility="visible";

If you want a different approach, just ask. me or someone else will be able to help you out.


Accepted Solution

nimaig earned 100 total points
ID: 6356187
Try this. Works in both IE and netscape

<script language="JavaScript">
     var imgCount = 9;
     var imgLoaded = 0;
     function dispDIV(){
          if(imgLoaded >= imgCount){
               }else if(document.layers){
<form name=myform>
<DIV name="divImg" id="divImg" style="position:absolute;visibility:hidden">
     <img src="http://otnxchange.experts-exchange.com/images/otn_logo_75x44_xp.gif" onLoad="javascript:dispDIV()">
     <img src="http://www.onjava.com/images/onjava/onjava_logo.jpg" onLoad="javascript:dispDIV()">
     <img src="http://careers.onjava.com/graphics/complogo_thomson.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/567037-468-6to4.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/538206-125-essentialjs2.gif" onLoad="javascript:dispDIV()">
     <img src="http://servedby.advertising.com/mnum=0000018953/logs=0/bins=1/site=0000034004/bnum=34004" onLoad="javascript:dispDIV()">
     <img src="http://otnxchange.experts-exchange.com/images/otn.gif" onLoad="javascript:dispDIV()">
     <img src="http://m.doubleclick.net/viewad/620465-altoweb_120x480_rev2__060501aaaa.gif" onLoad="javascript:dispDIV()">
     <img src="http://ad.doubleclick.net/557907/sgp2q01_336x280_WS_DEV_v_r3_c2.jpg" onLoad="javascript:dispDIV()">



Author Comment

ID: 6356646
Our intranet is used by IE and Netscape... we try to keep users current  -  within the last two revisions of both.

Expert Comment

ID: 6359165

<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 bgcolor="#FFFFFF" text="#000000" background="images/Celebrations.jpg" onLoad="MM_preloadImages('images/pic0.jpg','images/pic1.jpg','images/pic2.jpg','images/pic3.jpg','images/pic4.jpg','images/pic5.jpg')">

Hope this is pretty clear to you.
Hope this helps you.
Good Luck...:)

Author Comment

ID: 6361277
Thanks for your help... this code definitely got me going in the right direction.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I enable / disable a text box with a checkbox 3 23
alert(innerHTML); 8 32
Web experts ! HTML ! Javascript project for medical MRI sharing 24 49
multiple selects 23 48
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question