Window's onload, onresize, onscroll events, unlike other events, cannot be added with attachevent or AddEventListener.
That is to say, it can only do so (in the case of onload):
Copy Code code as follows:
Window.onload = function ()
{
// ...
};
But there is a problem, that is, if you want to add new event handlers for onload, you cannot directly assign values to the Window.onload, otherwise the previous assignment will be overwritten.
can do this:
Copy Code code as follows:
var oldloadhandler = window.onload;
Window.onload = function ()
{
if (Oldloadhandler)
{
Oldloadhandler ();
}
Newloadhandler ();
};
In the EZJ, it is more convenient.
Copy Code code as follows:
$ (window). Ready (OnloadHandler1);
$ (window). Ready (ONLOADHANDLER2);
Description
We generally contact the onload event is document.body.onload, but this is actually due to IE misleading, the correct should be window.onload,window.onload in IE, Firefox, Chrome is effective.