473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

preloading images not working in firefox

Hi everybody,

I have a typical javascript images preloader, it works fine both on
Firefox and on IE in my intranet (local server).
It works fine on the Internet (remote server) in IE.

In Firefox it stops before loading every image.

Does image.onload function have some problems with little images?

Any ideas? I suppose there's another post with the same topic, if so
could you please give me the link?

Thank you in advance,
carlo

This is the function:

// images is an array of images name
function preloadImages(images) {
var imgPreload=new Array();
var total=images.length;
var now=0;

for(i=0;i<images.length;i++) {

imgPreload[i]=new Image();
imgPreload[i].onload=function() {
now++;
if (now==total)
alert("OK!");
}
imgPreload[i].src = images[i];
};
}

Oct 2 '06 #1
3 9488
li*******@gmail.com wrote:
Hi everybody,

I have a typical javascript images preloader, it works fine both on
Firefox and on IE in my intranet (local server).
It works fine on the Internet (remote server) in IE.

In Firefox it stops before loading every image.
Are you seeing the difference in the way IE and FF cache images? What
happens if you clear the cache in FF?
--
Ian Collins.
Oct 2 '06 #2
li*******@gmail.com wrote:
Hi everybody,

I have a typical javascript images preloader, it works fine both on
Firefox and on IE in my intranet (local server).
It works fine on the Internet (remote server) in IE.

In Firefox it stops before loading every image.

Does image.onload function have some problems with little images?

Any ideas? I suppose there's another post with the same topic, if so
could you please give me the link?

Thank you in advance,
carlo

This is the function:

// images is an array of images name
I'm not sure that's a good name for a variable as there is a
document.images collection already - it might get confusing for someone
maintaining your code.

function preloadImages(images) {
var imgPreload=new Array();
Usually a global variable is used so that it persists after the
function has finished (see below).

var total=images.length;
var now=0;

for(i=0;i<images.length;i++) {
Variables like "i" should be kept local using the var keyword unless
there is a good reason to make them global:

for(var i=0; i<images.length; i++) {

>
imgPreload[i]=new Image();
imgPreload[i].onload=function() {
now++;
if (now==total)
alert("OK!");
}
imgPreload[i].src = images[i];
};
}
Typically your function will finish running well before the images have
finished loading. At that point, any local variables (including the
images array) will be available for garbage collection. It is very
likely that when you use this over the internet, the images haven't all
finished loading when the function ends so some never do.

When used locally, the images load faster and get to complete - the
simple solution is to make your images array global.

If this is just for small menu images, consider using CSS rollovers,
then you don't need any pre-loading (or even script support).
--
Rob

Oct 2 '06 #3
Ok, thanks for the answers.

First of all let me tell you that the page I'm preloading the images
for is in a new window (kind of popup) and there my preloader stops
before loading everything, instad if I call the page directly in
Firefox (without popping out the window) this script works fine.

Then, thanks to your advices, I've changed the variable name from
"images" to "myImages" and I've set the "i" variable as local.

And still didn't work fine.

Finally I've changed the imgPreload array from local to global and
suddeny evertyhing worked out. So yep I suppose it was something
relates to garbage collector as you told.

This is not a rollover-images preloader, I want to preload many images
(kind of big ones) in an horizontal-scrolling layout, so I want to
prevent my users from scrolling to not fully loaded sections.

Thank you.
Bye
carlo

Oct 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
2
by: Julie | last post by:
Hi, I'm trying to change images on a website without reloading the whole page and use the following code to preload the images: var preloadFlag = false; function preloadImages() { if...
6
by: michaaal | last post by:
Is this the correct way to preload an image...? Var Image1 = new Image() ....And then when I'm ready to use the image I can do this...? Button1.src=Image1.src ....Or am I just telling...
2
by: Stevio | last post by:
In my web page I preload images so that when a user clicks on a part of the image, the image changes. The images are used to display 4 tabs. Each image shows a different tab as highlighted. If a...
2
by: Van der Weij | last post by:
Hi, I want to preload some images for a webpage _and_ determing their width and height. The problem is that the scripts continue while the images are loaded in the background, while I need the...
2
by: windandwaves | last post by:
Hi Gurus Preloading images has got to be JS 101. However, it does not seem to be working. Here is the function that I am using. I added the alerts to make sure it is working and all the right...
40
by: Geoff Cox | last post by:
Hello, I am still having problems - apologies if the answer is in previous postings! I now have, in the header, <sctipt> var myimages=new Array();
3
by: giladg22 | last post by:
Hi All, I need some help resolving a pretty tricky problem. I have a javascript application running from a CD. The script preloads between 500 to 1000 jpegs (about 40K each) to the IE. The IE...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.