Hook a javascript event to page load

If you don't want to explicitly assign window.onload or use a framework, consider:

<script type="text/javascript">
function startClock(){
    //do onload work
}
if(window.addEventListener) {
    window.addEventListener('load',startClock,false); //W3C
} else {
    window.attachEvent('onload',startClock); //IE
}
</script>

http://www.quirksmode.org/js/events_advanced.html


Insert this anywhere in the body of the page:

<script type="text/javascript">
window.onload = function(){
    //do something here
}
</script>