Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript preload images function

Posted on 2004-04-06
5
Medium Priority
?
1,048 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

730 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