I am adding jQuery and swf library dynamically, onloading these libraries i am calling a method but the method is called twice, it works fine on local but on website it(methodCall()) fires 2 times.
function importJS(src, look_for, onload) {
//if already exists
if (eval("typeof " + look_for) != 'undefined'){
wait_for_script_load(look_for, onload);
return 0;
}
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', src);
if (onload) wait_for_script_load(look_for, onload);
var head = document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(s);
} else {
document.body.appendChild(s);
}
}
function wait_for_script_load(look_for, callback) {
var interval = setInterval(function() {
if (eval("typeof " + look_for) != 'undefined') {
clearInterval(interval);
callback();
}
}, 50);
}
(function(){
importJS('http://xyz.com/jquery.js', 'jQuery', function() {
importJS('http://xyz.com/swfobject.js', 'swfobject', function() {
methodCall();
});
});
})();