Solved

Javascript preload images function

Posted on 2004-04-06
5
1,028 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now