I have a single page application with different tabs. I want to include a Google chart only on one specific tab without directly loading the charts js file, jsapi, unless that tab is accessed.
To achieve this, I need to dynamically add the JavaScript as shown below:
var script = document.createElement('script');
script.src = '//http://www.google.com/jsapi?ext.js';
document.body.appendChild(script);
The problem arises when trying to detect if the JavaScript has been fully loaded so that I can proceed accordingly:
if (whenJspaiLoaded()) {
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart); //my custom function
}