Last active
September 12, 2015 14:13
-
-
Save rajanand02/dd68244fe3238f8d05b9 to your computer and use it in GitHub Desktop.
calling onload function multiple times without overriding the previously called function
This file contains hidden or 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
<!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