addLoadEvent

function addLoadEvent(func) {  
    var oldonload = window.onload;

    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}```

usage:  

addLoadEvent(firstFunction);


addLoadEvent(secondFunction);```

Take a memo, I saw this script in DOM scripting,the book I was reading, and it’s written by Simon Willison (http://simon.incutio.com/)

tzangms

Read more posts by this author.

Subscribe to Oceanic / 海海人生

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!