473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Image Question

Is there a Javascript way to check if an image has been rendered on the
page ? For example if my HTML includes :

<img name="testImg" src="images/one.gif">

is there anyway to tell using Javascript post page load if that image
has actually been loaded ?

Jul 20 '05 #1
5 1065
Greg Griffiths wrote:
Is there a Javascript way to check if an image has been rendered on the
page ? For example if my HTML includes :

<img name="testImg" src="images/one.gif">

is there anyway to tell using Javascript post page load if that image
has actually been loaded ?


<img onload="function(){whatever}"
Mick
Jul 20 '05 #2
"Mick White" <mw******@BOGUSrochester.rr.com> wrote in message
news:KC*******************@twister.nyroc.rr.com...
Greg Griffiths wrote:
Is there a Javascript way to check if an image has been rendered on the
page ? For example if my HTML includes :

<img name="testImg" src="images/one.gif">

is there anyway to tell using Javascript post page load if that image
has actually been loaded ?


<img onload="function(){whatever}"
Mick


Just a general note:
Some browsers don't support the onload event for images (i.e. Opera) so be
sure to provide a graceful and accessible alternative if possible.
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: http://www.andrewu.co.uk/about/conta...=newsgroup_clj
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004
Jul 20 '05 #3
"Andrew Urquhart" <reply_via_contact_page@website_in.sig> writes:
Just a general note:
Some browsers don't support the onload event for images (i.e. Opera)
Opera does support the onload event. There was a bug somewhere around
7.11 (or was it 7.20) where it failed, but in general it works (and did
in Opera 6 as well).
so be sure to provide a graceful and accessible alternative if
possible.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:hd**********@hotpop.com...
"Andrew Urquhart" <reply_via_contact_page@website_in.sig> writes:
Just a general note:
Some browsers don't support the onload event for images (i.e. Opera)


Opera does support the onload event. There was a bug somewhere around
7.11 (or was it 7.20) where it failed, but in general it works (and did
in Opera 6 as well).

Doh, I'm using 7.23 and yes it does work!

Actually I now know why I've always thought it didn't and it's not because
of the bug you mention, it's because I've always tested for the method to
see if it exists before I try and use it, and it's only just dawned on me
that Opera and other browsers handle this differently. For example:

var objImg = new Image();
objImg.src = "http://www.andrewu.co.uk/pix/xml.gif";
alert(typeof objImg.onload);
objImg.onload = function() {var dummy = null};
alert(typeof objImg.onload);

IE has a native or 'placeholder' onload method and returns "object" for the
first alert whereas Opera and Mozilla return "undefined". I always took the
latter browsers behaviour to mean that they didn't support the event, in the
same vain as:

if (document.getElementById) {
// Method supported
}
else {
// Method not supported
}
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: http://www.andrewu.co.uk/about/conta...=newsgroup_clj
Jul 20 '05 #5
That is all useful - also the ONERROR event - but what I was looking for
was a script that I could run once a page has loaded - as the content
is being sourced from another server and the images may be unavailable
due to permissions - that would process each image and then detect the
missing ones.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6

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

Similar topics

10
by: Fred Nelson | last post by:
Hi: I have programmed in VB.NET for about a year and I'm in the process of learing C#. I'm really stuck on this question - and I know it's a "newby" question: In VB.NET I have several...
68
by: Nak | last post by:
Hi there, This might sound like a silly question but, technically could an image object be used for any image format? For example if I were to make plugins for my application, could they be...
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
4
by: LT.Ang | last post by:
I am developing an application that possibly opens very large images - bmp, jpeg, tiff. I have 2 questions: Language: C#, VS .NET 2003. 1. When the program opens a BMP image, the amount of...
6
by: David Stone | last post by:
I have a simple question about the alt content of area elements within an image map: is it redundant to include phrases such as "link to..." or "jump to..."? My initial thought is 'yes', since...
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,...
1
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.