Why does [removed] work while [removed] doesn't?

后端 未结 2 892
别那么骄傲
别那么骄傲 2020-12-17 03:11

Can anyone tell me why the following page doesn\'t trigger an alert when it loads? If I use window.onload instead of document.onload it works. Why

相关标签:
2条回答
  • 2020-12-17 03:18

    The event handler is onload not document.onload. It hangs directly off the window object (which is the default object).

    0 讨论(0)
  • 2020-12-17 03:36

    The simplest answer is that it just wasn't designed that way. The browser executes the function attached to window.onload at the "end of the document loading process". It does not attempt to execute a function attached to document.onload.

    You could assign a function to document.onload but the browser will not do anything special with it.

    Some things to keep in mind (assuming you've just assigned a function to one or the other of window.onload or document.onload):

    1. window.onload === onload
    2. window.onload !== document.onload
    3. window !== document
    0 讨论(0)
提交回复
热议问题