Perhaps the question may be restated: how do I know my script is loaded in a html-page? Placing the script at the bottom of the page you make sure all the DOM-elements are available to your script. When you want to know if your script is available, you should check if the function to run is available. Maybe this constructor can help:
function Wait(what,action,id){
var _x = this,
rep = document.getElementById('report'),
cnt = 0,
timeout = 5,
interval = 100;
_x.id = id;
if (!(what instanceof Function)) {
return true; //or say something about it
}
function dowait() {
cnt += interval;
if (what())
{
clearInterval(_x.iv);
action();
return true;
}
if (cnt>(timeout*1000))
{
clearInterval(_x.iv);
//[do some timeout-action]
return true;
}
}
_x.iv = setInterval(dowait,interval);
}
The constructor takes a function (returning a boolean) as its first argument. Like
function(){return document.getElementById('someelement').innerHTML = '';}
So if you include this before your javascript, you can do something like:
var testfn =
function(){return document.getElementById('someElement').innerHTML = '';},
callback =
function(){alert('someElement is empty')},
dummy = null;
window.onload=function(dummy=new Wait(testfn,calllback);