JavaScript (Client/Server)

JavaScript – Executing Multiple window.onload events on a webpage

For executing multiple window.onload add this script to the head head section:

<script language=”javascript” >
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func
} else {
window.onload = function() {
if (oldonload) {
oldonload()
}
func()
}
}
}
</script>

Add Function to window.onload event use :

addLoadEvent(FunctionToRunOnPageLoad);

“or”

addLoadEvent(function() {
/* code to run on page load *
});

You Might Also Like