Why doesn't 'load' event handler bound to an <applet> get called?

老子叫甜甜 提交于 2020-01-17 12:41:26

问题


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.


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/5926424/why-doesnt-load-event-handler-bound-to-an-applet-get-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!