The onload, onresize, and onscroll events of windows are different from other events. They cannot be added using attachEvent or addEventListener.
That is to say, it can only be like this (take onload as an example, the same below ):
Copy codeThe Code is as follows:
Window. onload = function ()
{
//...
};
However, when you want to add a new event handler for onload, you cannot assign a value to window. onload directly. Otherwise, the previous assignment will be overwritten.
You can do this.:
Copy codeThe Code is as follows:
Var oldLoadHandler = window. onload;
Window. onload = function ()
{
If (oldLoadHandler)
{
OldLoadHandler ();
}
NewLoadHandler ();
};
In ezj, it is more convenient.
Copy codeThe Code is as follows:
$ (Window). ready (onloadHandler1 );
$ (Window). ready (onloadHandler2 );
Description
The onload event we normally contact is document. body. onload, but this is actually caused by incorrect IE. the correct one should be window. onload, window. onload is valid in IE, Firefox, and Chrome.