473,668 Members | 2,261 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.getEle mentById("theIm g");
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.getEle mentById("theMa p");
if(newImage.com plete) {
image.src = newImage.src;
} else {
setTimeout("swa pImage()", 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 10198
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
6203
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 onmousedown event could bubble up to an onload event. NOTE: If you put an alert() statement in the onmousedown event handler the body onload event doesn't get fired.
4
5877
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 I can't get onclick to fire on the rendered Thumbview object. What's strange is that onmouseover fires. Can anyone see a way? <html><head><title>test</title></head> <body onload="Init()">
1
2381
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 : function resize(){ displayFrm = document.getElementById("ifrmDisplay"); innerDoc = (displayFrame.contentDocument) ?displayFrm.contentDocument : displayFrm.contentWindow.document;
5
1913
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 before the page has comleted loading, which is necesary when one uses <body onLoad=""> Hope it's clear.
6
22122
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 I want to know how can I have the mousedown and mouseup buttons events. I think that I have to do this in JavaScript. Can you help me on this?
2
6452
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 images. When doing e.g. var img = new Image(); img.onload = function (evt) { alert(this); }; img.src = 'whatever.gif';
7
1941
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 and the next and previous buttons are added again and again. Please help meto solve the problem. The full html and javascript are attached for your conviniet. HTML ------- <HTML> <HEAD> <META http-equiv="Content-Language" content="en-us">
0
8374
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8791
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2784
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 we have to send another system
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.