// This will be called after pressing a button. function openPage(page){ // create the script element and attached var oHead=document.getElementsByTagName("head")[0]; var newScript=dhtmlLoadScript("blabla.js","myElementID"); oHead.appendChild(newScript); newScript.onload=function(){ alert('sds'); } }