Javascript: What argument does the function specified in body's onload event get called with?


Similar to this question, my HTML looks like this:

<body id="body" onload="loader()">
</body>

I always assume, as this doc says, that onload is given no arguments. However, I named the argument, and did some deep inspection, and found that I got an object looking like this:

{originalTarget : DOM, 
preventCapture : function, 
target : DOM, 
cancelable : Bool, 
currentTarget : DOM, 
timeStamp : Int, 
bubbles : Bool, 
type : String, 
eventPhase : Int, 
preventDefault : function, 
initEvent : function, 
stopPropagation : function, 
CAPTURING_PHASE : Int, 
AT_TARGET : Int, 
BUBBLING_PHASE : Int, 
explicitOriginalTarget : DOM, 
preventBubble : function,
isTrusted : Bool, 
MOUSEDOWN : Int, 
MOUSEUP : Int, 
MOUSEOVER : Int, 
//... (more constants)
}

Anyone have any idea what that thing is, or what its classname might be?

That appears to be the standard JavaScript DOM Event object. It describes the nature of the event that your function is handling.

UPDATE In response to comment discussion:

Different browsers supply the Event object in different ways:

  • IE never passes it as an argument to the function and instead uses the window.event property.
  • Firefox will pass it as the first argument.
  • Chrome seems to do both.