Skip to content

Instantly share code, notes, and snippets.

@nyov
Created February 1, 2011 18:12
Show Gist options
  • Save nyov/806300 to your computer and use it in GitHub Desktop.
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
/**
* @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