October 10, 2008

onload event in javascript

Nikolai Kordulla


You can add a to the body tag. But what, if you want to change the onload event programatically, or if you cant change the body tag? Just use this code (tested on safari, chrom, ie6, ie7 and firefox):
    /* for Mozilla */
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", init, false);

    /* for Internet Explorer */
    /*@cc_on @*/
    /*@if (@_win32)
        document.write("<script defer src='http://coderpeek.com/js/ie_onload.js'><"+"/script>");
    /*@end @*/

    /* for other browsers */
    window.onload = init;



Leave a Reply

Don't enter anything here:
Name (required) Invalid name
Mail (will not be published) (required) Invalid mail
Website Invalid url

Content couldnt be empty.