When do they fire?(他们什么时候开火?)
window.onload
In some browsers it now takes over the role of document.onload
and fires when the DOM is ready as well.
(在某些浏览器中,它现在接管了document.onload
的角色,并在DOM准备好时触发。)
document.onload
How well are they supported?(他们的支持程度如何?)
window.onload
appears to be the most widely supported.
(window.onload
似乎是最广泛支持的。)
In fact, some of the most modern browsers have in a sense replaced document.onload
with window.onload
.(实际上,一些最现代的浏览器在某种意义上用window.onload
替换了document.onload
。)
Browser support issues are most likely the reason why many people are starting to use libraries such as jQuery to handle the checking for the document being ready, like so:
(浏览器支持问题很可能是许多人开始使用诸如jQuery之类的库来处理文档准备就绪的原因,如下所示:)
$(document).ready(function() { /* code here */ });
$(function() { /* code here */ });
For the purpose of history.
(出于历史的目的。)
window.onload
vs body.onload
:(window.onload
vs body.onload
:)
A similar question was asked on codingforums a while back regarding the usage of window.onload
over body.onload
.
(关于window.onload
在body.onload
的使用情况,有人在编码论坛上提出了类似的问题。)
The result seemed to be that you should use window.onload
because it is good to separate your structure from the action.(结果似乎是你应该使用window.onload
因为将结构与动作分开是很好的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…