I also had issues with script.onload = runFunction; in IE8.
I tried jQuery.getScript and it worked perfectly for my needs. The only downside is having to wait for jQuery to be loaded before adding in the script.
However, since my callback functions utilize jQuery very heavily anyway I find this an extremely acceptable and very minor downside since it creates a very easy to use, cross-browser solution.
Update:
Here is a way of doing it without using jQuery:
(a modified solution from: https://mcmap.net/q/57654/-javascript-dynamic-script-loading-ie-problems)
var url = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
var headID = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type='text/javascript';
script.src=url;
//for nonIE browsers
script.onload=function(){
addVideo();
}
//for IE Browsers
ieLoadBugFix(script, function(){
addVideo();}
);
function ieLoadBugFix(scriptElement, callback){
if (scriptElement.readyState=='loaded' || scriptElement.readyState=='completed') {
callback();
}else {
setTimeout(function() {ieLoadBugFix(scriptElement, callback); }, 100);
}
}
headID.appendChild(script);
onload
for scripts in ie unfortunately. Have you found a way to do that? – Quinte