Solved

Javascript preload images function

Posted on 2004-04-06
5
1,029 Views
Last Modified: 2008-01-09
How can I amend this preload images function to not receive images names as arguments but to add image names to the array within the function.

function preloadImages() {
 var d=document; if(d.images){ if(!d.p) d.p=new Array();
   var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
0
Comment
Question by:ncw
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10766283
And where should come the image file names from?
If you call that function after <img> definitions or onLoad, then you do not need no preload.
And before the <img> are not scanned you can not see their src definitions.

0
 
LVL 16

Accepted Solution

by:
jaysolomon earned 125 total points
ID: 10766426
That code looks like it is Macromedia Preload that comes with dreamweaver

i use this
<head>
<script>
var img1 = new Image();
      img1.src = "images/image1.gif";
var img2 = new Image();
      img2.src = "images/image2.gif";
var img3 = new Image();
      img3.src = "images/image3.gif";
var img4 = new Image();
      img4.src = "images/image4.gif";
</script>
</head>



or you can load all of them in a hidden DIV and they will load without seeing them
0
 
LVL 1

Author Comment

by:ncw
ID: 10766853
The problem I'm hoping to solve is that not all the images load correctly, but this might just be on my local IIS. I wanted to do one list of image names and add to an array at the beginning of the function, rather than trying to find the image names in amongst the js function code
0
 
LVL 7

Expert Comment

by:brgivens
ID: 10767216
IIS does that locally for some strange reason.  It's very annoying, but if you test your page on a server the images will probably come up normally.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now