<img> onload vs complete

M

manu3d

Hi everybody,

I'm using the event "onload" to trigger a function when an
image has been preloaded. But it seems to me that the
function is triggered right at the beginning of the transfer
from remote to local rather than at the end of it.

Can anybody confirm this?

Thank you.

Manu
 
Y

Yanick

http://www.w3schools.com/jsref/jsref_onload.asp

has your information. Don't you love W3Schools ? :)

If you have troubles running your code, I suggest one of the following
:

1) verify if you have errors using alert debug windows and such (i.e. :
alert( var_to_test );)

2) use setTimeout() to delay the execution of the code

3) employ this to wrap your JS inside the <img> event attribute :

<img src="blah.gif" onload="//<![CDATA[
/** some js code here **/
//]]>" />

Read about it here : http://en.wikipedia.org/wiki/CDATA

But frankly, good coding rarely make it to solution 2) as it should run
correctly in solution 1).

Hope this helps.
 
R

Richard Cornford

Yanick said:
http://www.w3schools.com/jsref/jsref_onload.asp

has your information. Don't you love W3Schools ? :)

Yes; partial information and falsehoods put across as if it was
definitive.

3) employ this to wrap your JS inside the <img> event attribute :

<img src="blah.gif" onload="//<![CDATA[
/** some js code here **/
//]]>" />

When you have absolutely no idea why you are recommending something it
would probably be better not to mention it at all. This is a mystical
incantation, and can achieve nothing.
<snip>

A page that never suggests the above nonsense, or even implies anything
about it.

Richard.
 
R

Richard Cornford

Joe said:
Richard said:
Yanick wrote:
3) employ this to wrap your JS inside the <img> event attribute :

<img src="blah.gif" onload="//<![CDATA[
/** some js code here **/
//]]>" />

When you have absolutely no idea why you are recommending
something it would probably be better not to mention it at
all. This is a mystical incantation, and can achieve nothing.

Using CDATA is not a 'mystical incantation' when used as required
by the XML application to set aside parsing the CDATA content.
<snip>

Which is irrelevant to placing CDATA style mark-up inside the value of
an intrinsic event attribute in either HTML or XHTML. In neither case
could that CDATA style mark-up ever be interpreted as declaring CDATA,
and the result only avoids being a syntax error by being the text of
comments. Given that, the above most certainly is a mystical
incantation; it does precisely nothing in reality and is only being
'used' (rather than being weeded out as an obvious error) because it
does precisely nothing in reality.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top