473,799 Members | 3,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Knowing when graphics have loaded


I have an application where the user loads graphics from another site.
Presently I advise the user to wait for graphics to load before
clicking on adjustments. Ideally, I would prefer a closed-loop approach
where code would recognize completion of loading and automatically
enable the adjustments. Any ideas on how I can tap into what my browser
knows would be appreciated.

Jan 5 '06 #1
13 1692
a1*****@aol.com wrote:
I have an application where the user loads graphics from another site.
Presently I advise the user to wait for graphics to load before
clicking on adjustments. Ideally, I would prefer a closed-loop approach
where code would recognize completion of loading and automatically
enable the adjustments.
No, you would not.
Any ideas on how I can tap into what my browser knows would be
appreciated.


I assume we are talking about HTML 4.01/XHTML 1.0:

Use the `onload' event handler of the `img' element (object). Since
it is non-standard, you will have to assign it to the element when
the `load' event of the `body' element fires (hence use the `onload'
event handlers).
PointedEars
Jan 5 '06 #2
Since the onload event in the body tag is supposedly called when the
images are done loading, couldn't the controls for adjustments be
disabled until the onload function enables them?

Jan 6 '06 #3

Thomas 'PointedEars' Lahn wrote:
a1*****@aol.com wrote:
I have an application where the user loads graphics from another site.
Presently I advise the user to wait for graphics to load before
clicking on adjustments. Ideally, I would prefer a closed-loop approach
where code would recognize completion of loading and automatically
enable the adjustments.


No, you would not.
Any ideas on how I can tap into what my browser knows would be
appreciated.


I assume we are talking about HTML 4.01/XHTML 1.0:

Use the `onload' event handler of the `img' element (object). Since
it is non-standard, you will have to assign it to the element when
the `load' event of the `body' element fires (hence use the `onload'
event handlers).
PointedEars


I have found that a onload = "somefuncti on" statement within the img
tag does not fire and assume this is what you mean by the 'onload'
event handler being non- standard? If so then how does one assign a
handler to a specific element?

Herbert

Jan 6 '06 #4

James Black wrote:
Since the onload event in the body tag is supposedly called when the
images are done loading, couldn't the controls for adjustments be
disabled until the onload function enables them?


I use the onload event in the body tag to position and size objects on
my page. This works well. After loading, I need to detect when new
images have downloaded. My browser detects this event and changes the
contents of the status bar from the URL to the word, Done. At this
point, I would like code to enabled my controls.

Herbert

Jan 6 '06 #5
James Black wrote:
Since the onload event in the body tag is supposedly called when the
images are done loading,
No, it is not. The `load' event occurs when the document is loaded,
that is the DOM tree is complete. That does not necessarily include
that all referred resources have loaded.
couldn't the controls for adjustments be disabled until the onload
function enables them?


Since the `load' event does not ensure that the referred resources are
fully loaded, no.
PointedEars
Jan 6 '06 #6
a1*****@aol.com wrote:
Thomas 'PointedEars' Lahn wrote:
a1*****@aol.com wrote:
> Any ideas on how I can tap into what my browser knows would be
> appreciated.
I assume we are talking about HTML 4.01/XHTML 1.0:

Use the `onload' event handler of the `img' element (object). Since
it is non-standard, you will have to assign it to the element when
the `load' event of the `body' element fires (hence use the `onload'
event handlers).
[...]


I have found that a onload = "somefuncti on" statement within the img
tag does not fire and assume this is what you mean by the 'onload'
event handler being non- standard?


If you have otherwise Valid markup, "somefuncti on" represents a function
_call_ to a declared function ["bar()"] and no script error occurs[2],
then yes. I have observed that the `onload' event handler attribute for
the `img' element is supported by some browsers, yet the resulting markup
is still not Valid HTML.

[1] <URL:http://validator.w3.or g/>
[2] <URL:http://jibbering.com/faq/#FAQ4_43>
If so then how does one assign a handler to a specific element?


Use the `onload' event handler of the `body' element. Quickhack:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function _addEventListen er(o, sEvent, fListener, bUseCapture)
{
if (o)
{
if (isMethodType(t ypeof o.addEventListe ner)
&& isMethodType(ty peof fListener))
{
o.addEventListe ner(sEvent, fListener, !!bUseCapture);
result = true;
}
else if (isMethodType(t ypeof o.attachEvent)
&& isMethodType(ty peof fListener))
{
result = o.attachEvent(" on" + sEvent, fListener);
}
else
{
o["on" + sEvent] = fListener;
result = (o["on" + sEvent] == fListener);
}
}
}

function addEventListene rToImg(sName, sEvent, fListener, bUseCapture)
{
var img;
if (typeof document != "undefined"
&& document.images
&& (img = document.images[sName]))
{
return _addEventListen er(img, sEvent, fListener, bUseCapture);
}

return false;
}

function bar()
{
// ...
}
</script>
...
</head>

<body ... onload="addEven tListenerToImg( 'foo', 'load', bar);">
...
<img ... name="foo">
...
</body>
PointedEars
Jan 6 '06 #7
VK

a1*****@aol.com wrote:
James Black wrote:
Since the onload event in the body tag is supposedly called when the
images are done loading, couldn't the controls for adjustments be
disabled until the onload function enables them?


I use the onload event in the body tag to position and size objects on
my page. This works well. After loading, I need to detect when new
images have downloaded. My browser detects this event and changes the
contents of the status bar from the URL to the word, Done. At this
point, I would like code to enabled my controls.


So there is the problem??
Any browser since Netscape 3.0 supports onload / onerror handlers for
images. So simply
<img src="nyImage.jp g" onload="notifyO bserver(this)"
onerror="notify Observer(this)" >

With regular security limitations of course: you're not getting events
from frame/iframe from another domain; also recent browsers (like
Firefox) may be set to block download of images from another domains.
Also on older browsers animated GIF's may trig "load" event on each
animation loop. Otherwise there are no problems whatsoever. Unless
there are extra circumstances?

Jan 7 '06 #8

Thomas 'PointedEars' Lahn wrote:
a1*****@aol.com wrote:
Thomas 'PointedEars' Lahn wrote:
a1*****@aol.com wrote:
> Any ideas on how I can tap into what my browser knows would be
> appreciated.

I assume we are talking about HTML 4.01/XHTML 1.0:

Use the `onload' event handler of the `img' element (object). Since
it is non-standard, you will have to assign it to the element when
the `load' event of the `body' element fires (hence use the `onload'
event handlers).
[...]


I have found that a onload = "somefuncti on" statement within the img
tag does not fire and assume this is what you mean by the 'onload'
event handler being non- standard?


If you have otherwise Valid markup, "somefuncti on" represents a function
_call_ to a declared function ["bar()"] and no script error occurs[2],
then yes. I have observed that the `onload' event handler attribute for
the `img' element is supported by some browsers, yet the resulting markup
is still not Valid HTML.

[1] <URL:http://validator.w3.or g/>
[2] <URL:http://jibbering.com/faq/#FAQ4_43>
If so then how does one assign a handler to a specific element?


Use the `onload' event handler of the `body' element. Quickhack:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function _addEventListen er(o, sEvent, fListener, bUseCapture)
{
if (o)
{
if (isMethodType(t ypeof o.addEventListe ner)
&& isMethodType(ty peof fListener))
{
o.addEventListe ner(sEvent, fListener, !!bUseCapture);
result = true;
}
else if (isMethodType(t ypeof o.attachEvent)
&& isMethodType(ty peof fListener))
{
result = o.attachEvent(" on" + sEvent, fListener);
}
else
{
o["on" + sEvent] = fListener;
result = (o["on" + sEvent] == fListener);
}
}
}

function addEventListene rToImg(sName, sEvent, fListener, bUseCapture)
{
var img;
if (typeof document != "undefined"
&& document.images
&& (img = document.images[sName]))
{
return _addEventListen er(img, sEvent, fListener, bUseCapture);
}

return false;
}

function bar()
{
// ...
}
</script>
...
</head>

<body ... onload="addEven tListenerToImg( 'foo', 'load', bar);">
...
<img ... name="foo">
...
</body>
PointedEars


I thank you for the code. It works fine for IE 6.0 and when I figure
out how it works then perhaps I could get the code to work with my
Opera and Netscape browsers.

Herbert

Jan 7 '06 #9
a1*****@aol.com wrote:
Thomas 'PointedEars' Lahn wrote:
[...]
Use the `onload' event handler of the `body' element. Quickhack:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function _addEventListen er(o, sEvent, fListener, bUseCapture)
{
if (o)
{
if (isMethodType(t ypeof o.addEventListe ner)
&& isMethodType(ty peof fListener))
{
o.addEventListe ner(sEvent, fListener, !!bUseCapture);
result = true;
}
else if (isMethodType(t ypeof o.attachEvent)
&& isMethodType(ty peof fListener))
{
result = o.attachEvent(" on" + sEvent, fListener);
}
else
{
o["on" + sEvent] = fListener;
result = (o["on" + sEvent] == fListener);
}
}
}

function addEventListene rToImg(sName, sEvent, fListener,
bUseCapture)
{
var img;
if (typeof document != "undefined"
&& document.images
&& (img = document.images[sName]))
{
return _addEventListen er(img, sEvent, fListener, bUseCapture);
}

return false;
}

function bar()
{
// ...
}
</script>
...
</head>

<body ... onload="addEven tListenerToImg( 'foo', 'load', bar);">
...
<img ... name="foo">
...
</body> [...]


Please trim your quotes to the minimum required for retaining the context.

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1P ost>
I thank you for the code. It works fine for IE 6.0 and when I figure
out how it works
Why, you could ask its author ...

It is fairly simple: when the `load' event of the `body' element fires,
the `img' element named "foo" is added an event listener for its `load'
event, where several approaches to do so are feature-tested and the
first positive tested feature is used[0]. That event listener, `bar',
is called when the `img' element's `load' event fires.

[0] Therefore, an attempt at improving its efficiency and reliability:

function _addEventListen er(o, sEvent, fListener, bUseCapture)
{
var result = false;

if (o && sEvent && isMethodType(ty peof fListener))
{
if (isMethodType(t ypeof o.addEventListe ner)
{
o.addEventListe ner(sEvent, fListener, !!bUseCapture);
result = true;
}
else
{
if (isMethodType(t ypeof o.attachEvent))
{
result = o.attachEvent(" on" + sEvent, fListener);
}

if (!result)
{
o["on" + sEvent] = fListener;
result = (o["on" + sEvent] == fListener);
}
}
}

return result;
}

Note that the feature test for addEventListene r() is still not sufficient as
it only tests for existence, not functionality. If someone could come up
with a reliable method to determine if addEventListene r() was successful
(since it does not have a return value or exception specified), that would
make this approach less error-prone.
then perhaps I could get the code to work with my Opera and Netscape
browsers.
And what exactly does not work there?

The code does work with Netscape (presumably 2.0+[1], tested with [2],
[3] and [4]), and Opera[5]. (However, it should be noted that in
Netscape 4.8 and animated GIFs, the `onload' handler is triggered
there every time the animation loops.) Opera even supports
elemObjRef.addE ventListener('l oad', ...) for HTMLImageElemen t objects
referred to by `elemObjRef', although there is no such event for `img'
elements according to W3C DOM Level 2 Events 1.0; ISTM it is implementing
W3C WG Note W3C DOM Level 3 Events 1.0 here, where the event applies to
such elements, being "a resource linked from the document."[6]

What you may encounter, of course, is that bar() will not be called on
creation of the `img' element if the `load' event of the `img' element
fired before the `load' event of the `body' element fires. The above
approach works quite reliably only if you want to handle `src' attribute
changes to the `img' element after it was first loaded.

I am not sure if there is always a viable workaround for that. A possible
workaround without invalid HTML would probably be to try to add the event
listener for the `load' event of the `img' element right after if was
included or at the end of the document's body element.

A possible workaround with Valid XHTML could be to augment the XHTML
DTD with the `onload' attribute for the `img' element, such as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d" [
<!ATTLIST img
onload CDATA #IMPLIED

]>

I have tested the former successfully in Netscape 4.8+, Firefox 1.5 and
Opera 8.51, and the latter (XHTML) successfully in Netscape 6.2.3+ (see
footnotes) and Firefox 1.5 using Gecko's XML parser (by serving
application/xhtml+xml).

What was most interesting to me when pursuing the latter approach is that
XML 1.0, which is used to define XHTML 1.0, explicitly allows the
latter[7], so it is indeed Valid markup and does not break the DTD
declaration. And there is also a disturbing fact: Even though the XHTML
1.0 Transitional DTD does not declare the `onload' attribute for the `img'
element, Gecko's XML parser in Standards Compliance Mode does not find
anything not well-formed with the markup when I omit the above ATTLIST
declaration; the W3C Markup Validator does.

Of course, a possible workaround with invalid HTML is to use the `onload'
attribute of the `img' element anyway, but I recommend against that.
HTH

PointedEars
___________
[1] <URL:http://research.nihons oft.org/javascript/jsref/doc1.htm#101084 2>
[2] Mozilla/4.8 [en] (X11; U; Linux 2.6.14.4-20051220.153223 +0100 i686)
[3] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4.1) Gecko/20020508
Netscape6/6.2.3
[4] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805
Netscape/7.2
[5] Opera/8.51 (X11; Linux i686; U; en)
[6]
<URL:http://www.w3.org/TR/DOM-Level-3-Events/events.html#Eve nts-eventgroupings-htmlevents>
[7] <URL:http://www.w3.org/TR/REC-xml/#NT-doctypedecl>
<URL:http://www.w3.org/TR/REC-xml/#NT-AttlistDecl>
"When more than one AttlistDecl is provided for a given element type,
the contents of all those provided are merged."
Jan 7 '06 #10

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

Similar topics

8
3038
by: IGC | last post by:
I have a requirement to record in a database when a file is finished downloading to the end-user. Currently when a user clicks a download icon for a file it directs to an ASP page that records the "hit" into a database, then I use a response.redirect "filename.exe" to point the user to the download. What I'm missing is knowing when the download is complete so I can update the database to show the file successfully completed its download....
2
1280
by: Brian Cryer | last post by:
I'm working on a VB.NET project where we are intending to use MSDE as our back-end database. The actual number of users is expected to be low and I don't have any concerns as to whether MSDE will be up to the job (most of the time). I'm aware that if we end up with lots of users connecting to our site at once (which may happen as certain times in the year when people need information for deadlines) then the performance governor in MSDE will...
2
1859
by: Bill S. | last post by:
Hey, I am trying to figure this out. The hyperlinks on my page open up a small popup window. I have no reason to refresh the parent page or what have you. I was living in a very happy world, with no problems or disturbances. However, a problem has since arisen: The search engines have indexed these popup pages. So, you load them, but there are no links on them, and there is no parent page. Many people would not check out the url and...
1
1346
by: Greg Lindstrom | last post by:
I have an odd problem that I'm sure someone here can help me solve. I am using Python 2.3 on a Linux box to process text files. At one point in my automated process, I have to zip and ship the files over to a Windows server running a proprietary package to do some manipulation to the file. Problem is that I need to know when the process completes processing the file. Complicating matters is that this package names the output file using...
2
2667
by: Niklas Ringdahl | last post by:
Hello. I am using databindings to bind my dataset to comboboxes, textboxes and labels. Some of my UI depends on knowing when the user changes the values, but I have some problems knowing when my dataset value is set in the controls. - SelectedIndexChanged event fires during the bind process, so I can't just use that - The binding don't seem to "kick in" until the tab page where the control
2
970
by: Greg | last post by:
Is there a way I can find out if a file is in use or not? My app is calling an external converter and doesn't wait for it to finish (would like it to, but doesn't appear that it can). The problem is, it never knows when the file the external converter writes to is finished. I've tried a few things, including waiting for the file attributes to become FileAttributes.Normal (which it never becomes). The file attribute is always...
7
2051
by: chad | last post by:
let's say I'm transferring a large file like 100MB over to a folder. The program detects when the file arrives. However, I can't figure out how to know when the file is totally transferred over. One unsuccessful method is to... dim fi as new fileinfo(newfile) fi.length returns the supposed size of the file. But it correctly
1
1393
by: GoogleNewsReaderMan | last post by:
Is there a way for me to know from within a given assembly when it gets loaded? If so, how can this be done? Thanks in advance!
0
1151
by: jaim | last post by:
In my web page there is a text 2nd number of your passcode when the page loaded , dynamicaaly each time number is getting changed. And also having the Combo box to select the values (0-9) this should match the text in the label. Is there any way to get the number in the text which is changing dynamically and parametrise the combox box values to match exactly same as labels
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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,...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7571
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
6809
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.