Override the window.onload javascript function


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/www/danfolkes.com/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

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();};

2 thoughts on “Override the window.onload javascript function”

Comments are closed.