The question is so like a zillion others here and on the web - How to check if DOM has loaded in Javascript? But here\'s the catch:
This works for all browsers and is short and concise:
var execute = function () { alert("executing code"); }; if ( !!(window.addEventListener) ) window.addEventListener("DOMContentLoaded", execute) else // MSIE window.attachEvent("onload", execute)