Created
February 1, 2011 18:12
-
-
Save nyov/806300 to your computer and use it in GitHub Desktop.
Reasonably portable, non-framework way of having your script set a function to run at load time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @source http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load#807997 | |
*/ | |
var yourFunctionName = function(){}; | |
if(window.attachEvent) { | |
window.attachEvent('onload', yourFunctionName); | |
} else { | |
if(window.onload) { | |
var curronload = window.onload; | |
var newonload = function() { | |
curronload(); | |
yourFunctionName(); | |
}; | |
window.onload = newonload; | |
} else { | |
window.onload = yourFunctionName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment