473,508 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Image.onload event firing too early in IE

I'm trying to come up with a solution for detecting when an image,
loaded by a script, has completely loaded. The Image.onload event is
fired after the image has loaded in Firefox but before loading has
completed in Internet Explorer. The function where I assign the
onload event handler looks like this:

var newImage = new Image();

function getImage(url) {
var image = document.getElementById("theImg");
newImage.onload = swapImage;
newImage.src = url;
}

As an attempt at a work-around, in the event handler function
swapImage() I have the following code:

function swapImage() {
var image = document.getElementById("theMap");
if(newImage.complete) {
image.src = newImage.src;
} else {
setTimeout("swapImage()", 250);
}
}

Unfortunately the new image's 'complete' property is set to true prior
to the image fully loading leaving me no better off.

I wondered if this behaviour might be related to the server not
providing the Content-length response header but the headers for the
image seem to be in order:

HTTP/1.x 200 OK
Server: Apache-Coyote/1.1
X-Cocoon-Version: 2.1.6
Vary: Host
Last-Modified: Tue, 25 Jan 2005 11:46:27 GMT
Accept-Ranges: bytes
Content-Type: image/jpeg
Content-Length: 168667
Date: Tue, 25 Jan 2005 11:45:27 GMT

I've considered setting a fixed delay in the event handler if the
browser is IE but I'm not really happy with that approach as the size
of the image to be loaded can be quite variable. The user's internet
connection speed is also unknown.

I'd be very interested in hearing from anybody who has a resolution to
this problem.

Kind regards,
Adam
Jul 23 '05 #1
1 10181
I've resolved this issue. The problem was not as I thought, related to
the behaviour of the onload event, but rather to a failure of IE to
cache the preloaded image. This meant that when the original image's
src attribute was modified to that of the new image there was no image
to load from the cache so a new request was made to the server.

The reason the image was not cached is the 'Vary' response header sent
by the application server (Apache Cocoon). This header is a directive
specifying which request headers are to be used in addition to the
request URI in determining if a suitable match exists in the cache. IE
will _not_ cache responses containing the Vary header unless the field
specified is the "User-Agent" field. For more detail on this issue
see: http://lists.over.net/pipermail/mod_...er/006826.html

Removing the 'Vary' header results in the preloaded images being cached
correctly and the code works as expected.

Cheers
Adam

Jul 23 '05 #2

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

Similar topics

2
6196
by: Bender | last post by:
Hi, I am wanting to capture an onmousedown event without firing the body tags onload event. Also, if anyone could explain why this happens that would be excellent. I can't see how an...
4
5861
by: joebob | last post by:
The following script if run in Internet Explorer should display a thumbview of a webpage that you point it to. To test it, replace test.htm with a valid html file. The problem I'm having is that...
1
2372
by: khothikhe | last post by:
Can someone help me here because this is really killing me! the problem is, i have this javascript code in my aspx page that i want it to work on almost all browsers, especially opera and safari...
5
1907
by: frizzle | last post by:
Hi there, ijust a quicky: I was wondering if the following is supported everywhere: <img src="spacer.gif" width="1" height="1" onLoad="doomething()"> That way i can launch/check a few things...
6
22115
by: ruca | last post by:
Hi gurus, I have a imagebutton in my WebForm, and I want that when I click (mouse down) on her the imagebutton change image and when I "unclick" (mouse up) change to the original image. Basically...
2
6425
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading...
7
1932
by: raknin | last post by:
Hi I have a carousel script. I want to load the carousel with a new set of pictures every time I press a button. The problem that I have that the script append the new pictures to the olds one...
0
7227
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
7127
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
7331
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
7391
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...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.