0

I am using Onload() to know when an image has been loaded. It has worked for years and still is working on my computer and can be found in the w3schools reference http://www.w3schools.com/jsref/event_img_onload.asp

I ran one of my few pages that have that through the validator and it does not like me using onload with image tags.

<a href='http://www.adobe.com/go/getflashplayer'>
<img src='./player/embed/get_flash_player.gif'  alt='Get Adobe Flash player' onload="triggercounter('test','Flash Failed') "/>
</a>

What is the preferred way to trigger an event when an image has loaded?

4

2 回答 2

2

You get the validator error message most probably because you are validating against HTML 4.01 or XHTML 1.0, which do not allow onload on img (only on body and frameset). HTML5 allows it on any element.

This is just the formal side of the matter. Whether the method actually works in browsers is a completely different matter.

于 2013-11-01T07:57:12.823 回答
-1

Firstly, avoid w3schools - the site's abhorrently out of date and incorrect on nearly everything - and isn't even associated with the W3C at all.

Then, simply change your onLoad to onload - HTML5/XHTML element attributes are lowercase and case-sensitive. Here's a handly list of 'global' attributes you can stick on nearly every HTML tag: 8. Global attributes

于 2013-11-01T07:23:09.570 回答