0

I want a callback that is executed after an <applet> element is loaded:

// Create element
var $applet = $("<applet></applet>");

// Attach handler
$applet.load(function() {
    alert('applet loaded');
});

// Set attributes
$applet.attr({
    style: 'position:absolute;left:-1px',
    name: 'TiddlySaver',
    code: 'TiddlySaver.class',
    archive: 'TiddlySaver.jar',
    width:'1',
    height:'1',
});

Why is the 'load' event handler not executed for an <applet> element? If I change the <applet> to an <img> element (with valid src attribute) the handler is executed.


According to the HTML 4.01 (which is the fundamental standard for web pages), only two elements have an onload attribute: body and frameset. Some other elements also support it as a proprietary extension (image is fairly common), but you should not expect any other element to do so.

HTML5 requires all HTML elements (except body, which is peculiar) to support a load event, but you can't depend on it being widely or fully implemented yet (if ever).

4

2 回答 2

2

根据 HTML 4.01(这是网页的基本标准),只有两个元素具有 onload 属性:body 和 frameset。其他一些元素也支持它作为专有扩展(图像相当常见),但您不应该期望任何其他元素这样做。

HTML5 要求所有 HTML 元素(除了 body,它是特殊的)来支持加载事件,但你不能依赖它被广泛或完全实现(如果有的话)。

于 2011-05-08T11:43:23.310 回答
1

From the jQuery documentation:

This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

That might be the reason why.

于 2011-05-08T12:09:29.613 回答