开发者

Append window.onload

开发者 https://www.devze.com 2023-03-20 07:46 出处:网络
How do I append window.onload in javascript.I want to be able to add a function to what might already be defined for window.onload.So if I have

How do I append window.onload in javascript. I want to be able to add a function to what might already be defined for window.onload. So if I have

<body onload="function1();">

I want to have "function1(); function2();" defined for the page load.

is there something like window.onload 开发者_Python百科+= "function2();";

Thanks.


You can call one method that calls another methods.

<body onload="function1();">


function function1(){
function2();
function3();
function4();
}

edit: but I would rather code a jQuery driven solution, by using:

$(function(){
// here you implement whatever you need, even call other functions.
});


You can have multiple "window.onload = function() { ... }" statements.

But if you want to use , maybe you can try something like this:

<body onload="func1(), func2(), func3()">


    if (window.addEventListener) // W3C standard
    {
      window.addEventListener('load', myFunction, false); // NB **not** 'onload'
    } 
    else if (window.attachEvent) // Microsoft
    {
      window.attachEvent('onload', myFunction);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消