About
Profile picture Gokhan Demir,
a computer geek in Istanbul.

E-mail me Send mail


Photo Of The Day


  • Island at Twilight, South Africa, 2003

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Pages


    Recent posts


    Recent comments


    Archive


    Authors


    Tags


    Categories


    Blogroll


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in

    Attaching Methods To Window Load Event

    by Gokhan Demir 11/16/2007 1:42:00 PM

    On the client side, if i want to attach some function for page load event, i used to implement the window.onload event :

    window.onload = func;
    
    But this approach has some difficulties. Because this will completely overwrite any other functions that were attached. So I began to search for a better solition. After visiting some saint google links, i got the answer. window.addEventListener (for mozilla,gecko, safari and konqueror), window.attachEvent (for internet explorer) and document.addEventListener (for opera 7) methods can be used for attaching any kind of method in a safe way. All i need to wrap these nifty methods into a function. Here is the code snippet that you can use :
    function AddOnload(func){
    if(window.addEventListener) 
    window.addEventListener('load', func, false);
    else if(document.addEventListener)
    document.addEventListener('load', func, false);
    else if(window.attachEvent)
    window.attachEvent('onload', func);
    }
    
    Happy codings ;)
    Powered by BlogEngine.NET
    Designed by FYFI, Adapted by Gokhan Demir