Re: img tag onload not validated

Henri Sivonen wrote:
> On Sep 28, 2008, at 23:40, Benjamin Hawkes-Lewis wrote:
[...]
>> In HTML 4.01 Transitional, only the BODY element may have an ONLOAD
>> attribute:
[...]
> onload on <img> is allowed in HTML5, so this can be resolved by
> upgrading the validation target.

"HTML5" is just a name for an incomplete sketch of a draft, so I don't see 
the point.

If you just want to pass validation, you can simply create a local copy of 
an HTML 4.01 DTD and edit it so that onload is allowed for <img>. You don't 
have to "buy" blindly whatever might be in an HTML5 DTD this week.

Of course, this would not affect the _functionality_ of the page. If there 
is reliable documentation on actual browser behavior that says that onload 
for <img> is well-supported, you could keep using it, though browser 
behavior may well change when it comes to "nonstandard" attributes.

To stay on the safe side, just use onload in the <body> element where it is 
"standard", and write your script so that it refers to the image as needed 
(e.g., using an id attribute for it). This way, your onload operations will 
take place in a well-defined order. (If several onload attributes are used 
and supported, what would be their execution order?)

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/ 

Received on Monday, 29 September 2008 15:03:10 UTC