The onload, onresize, and onscroll events of windows are different from those of other events. They cannot be added using attachEvent or addEventListener, so I think of some alternative methods, you can refer to the onload, onresize, and onscroll events of windows. Unlike 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 ):
The 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.:
The Code is as follows:
Var oldLoadHandler = window. onload;
Window. onload = function ()
{
If (oldLoadHandler)
{
OldLoadHandler ();
}
NewLoadHandler ();
};
In ezj, it is more convenient.
The 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.