Skip to content

Instantly share code, notes, and snippets.

@rajanand02
Last active September 12, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajanand02/dd68244fe3238f8d05b9 to your computer and use it in GitHub Desktop.
Save rajanand02/dd68244fe3238f8d05b9 to your computer and use it in GitHub Desktop.
calling onload function multiple times without overriding the previously called function
<!DOCTYPE html>
<html lang="es">
<head>
<title>Window On Load</title>
</head>
<body>
<h1>Window on load</h1>
</body>
<script type="text/javascript" charset="utf-8">
var helloWorld = function (){
console.log("Hello world");
};
var helloAnkit = function () {
console.log('hello Ankit');
};
var greet = function(message){
return function(){
console.log(message);
}
};
var onLoadFunction = function(fun) {
var previousFunction = window.onload;
if (typeof window.onload != 'function') {
window.onload = fun;
} else {
window.onload = function() {
if (previousFunction) {
previousFunction();
}
fun();
}
}
};
onLoadFunction(helloWorld);
onLoadFunction(greet('hey there'));
onLoadFunction(helloAnkit);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment