Solved

Javascript preload images function

Posted on 2004-04-06
5
1,039 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
[X]
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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

751 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