开发者

Body Onload Event

This code doesn't see开发者_StackOverflowm to work:

document.body.onload = function () { ... }

I know there is a onload event for the body tag in html, but how come you can't access it from JavaScript? Is window.onload same as <body onload="...

It basically never triggers.


  1. There is no body.onload. When you attach the event in the HTML code, it actually attaches to window.onload. So that's the one you should use.
  2. It only fires when all the resources (images, scripts, css files, etc.) have fully loaded.
  3. If there is another script which also tries to attach to the event (and almost all javascript frameworks do, like jQuery, ExtJS, etc.), then you might get a conflict there. Better attach to the event through the framework;
  4. How do you attach it? Maybe you attach the event handler too late, when the page is already loaded.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜