Best Practice: JavaScript Window onLoad usage and event handelers setup

Handy Copy & Paste window.onload and event hanelers setup snippet:

<script type=”text/javascript”>

var temp_f;
if( window.onload ) {
temp_f = window.onload;
}
window.onload = function () {
if( temp_f ) {
temp_f();
}
init();
}

function init(){
initPageEvents();
}

function initPageEvents(){
document.getElementById(‘linkClick’).onclick=function(){
linkClicked();
}
}

function linkClicked(){
alert(“ok”);
}
</script>

[..]

<a href=”#” id=”linkClick”>Link</a>

Leave a Reply

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