473,397 Members | 2,033 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,397 software developers and data experts.

Image onload handler - how to access the image object?

Good day

In an image onload handler, how do I access the image that just loaded?

If the image is attached to the document, I can access it using the field
window.event.srcElement. But I really don't want to attach the image to the
document until it has loaded (I plan to use it to replace an existing visible
low-res version of the same image). The onload handler is called for the
unattached image, but the window.event.srcElement is NULL.

I'm using IE 6.0, but I need a cross-browser solution.

Cheers!
Jul 23 '05 #1
1 2969
Roger Shrubber wrote:
<snip>
If the image is attached to the document, I can access it using the
field window.event.srcElement. But I really don't want to attach the
image to the document until it has loaded (I plan to use it to
replace an existing visible low-res version of the same image). The
onload handler is called for the unattached image, but the
window.event.srcElement is NULL.

I'm using IE 6.0, but I need a cross-browser solution.


Event handling functions are methods of objects (and are called as
such), in all methods (called as methods) the - this - keyword refers to
the object. So:-

var img = new Image();
img.onload = function(){
document.images['imgName'].src = this.src;
}
img.src = "http://example.com/image.gif";

Richard.
Jul 23 '05 #2

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

Similar topics

8
by: TheKeith | last post by:
I'm doing an image cycler but can't figure out why it keeps getting hung up on the third pic in the array? Here is what I have: ...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
2
by: inevercheckthisaddress | last post by:
I can't get Opera to fire an event when an image object's src has loaded. The test code I'm using is this - --------------------------------- window.onload=go function yo() { alert("yo"); }
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
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...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
4
by: Mark S. | last post by:
Hello, On a high volume page we have the following JavaScript: img = new Image() img.src = 'http://myserver.com/count.aspx?x=1'; and it works fine, but now we've added: img.onload =...
7
by: howardk | last post by:
I'm writing some code that loads a number of images, using the standard mechanism of assigning a src url to a newly constructed Image object, thus invoking the image-load operation. On a successful...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.