Override the window.onload javascript function


1. Creates a blank function
2. Checks onload for a function.
2a. Sets the originial onload function as temp
3. calls the new function initMap() before the originial temp onload function.

Pretty cool!

Code:

1
2
3
4
5
6
7
var temp=function(){ return 1;};
if( window.onload )
{
      //override "placeholder" with whatever already exists in onload
     temp = window.onload;
}
window.onload=function(){ TheFunctionYouWantToCall(); temp();};
Share and Enjoy:
  • Digg
  • StumbleUpon
  • Facebook
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • email
  • Google Buzz
  • Reddit

  1. #1 by Dallas Edwards on October 21, 2009 - 3:50 pm

    That’s excellent. I can actually use this right now at work. Thanks, Dan!

    • #2 by Daniel on October 21, 2009 - 3:56 pm

      thanks dal! anything to further the cause.

(will not be published)