Ye Meri Life Hai – Chirag Mehta

Executing JavaScript on page load

November 4th, 2009

Following code helps you to define any JS function to be called on page load. The tricky part of the code is that it waits until page is completely loaded.


<script>
function init() {
alert('Loaded');
}

var previousOnload = window.onload;
window.onload = function() {
if (previousOnload) {
alert('...loading ...');
previousOnload();
}

init();
}
</script>

Your email address will not be published. Required fields are marked *

*