ScottKing.com.au

Archive for March, 2010

Best Practice: JavaScript Window onLoad usage and event handelers setup

by on Mar.15, 2010, under CSS, JavaScript

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 Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...