Possible Duplicate:
how to check the script element load event accross browser without jquery
I'm writing a page to generate graphs for someone. I'm using the Google Charts API.
I want to load the API dynamically. I'm having problems with the 'google' global object. How can I detect whether it has been declared? If it were my own script I think I could use call back. Currently i have :
var addScript = function(src){
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= src;
head.appendChild(script);
}
var init = function (){
addScript('https://www.google.com/jsapi');
var waitForScript = setInterval(function(){
if(window['google']!==undefined){
window.clearInterval(waitForScript);
google.load('visualization', '1.0', {
'packages':['corechart']
});
}
},50);
}
Any help would be much appreciated!