Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1052
  • Last Modified:

Javascript preload images function

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
ncw
Asked:
ncw
1 Solution
 
ZvonkoSystems architectCommented:
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
 
jaysolomonCommented:
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
 
ncwAuthor Commented:
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
 
brgivensCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now