1

So i have the following code in index.html, and i got it from google's developer site, but now i need to run the function mapsResume() after the google maps api library finishes downloading.

function downloadJSAtOnload() {
  var element = document.createElement("script");
  element.src = "http://maps.googleapis.com/maps/api/js?libraries=places";
  document.body.appendChild(element);
  mapsResume();
}

mapsResume(){
/* lots of code */
}

if (window.addEventListener)
   window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
   window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
user1742835
  • 155
  • 1
  • 5
  • Possible duplicate of http://stackoverflow.com/questions/14644558/call-javascript-function-after-script-is-loaded – Gagan Aug 05 '15 at 05:43
  • Possible duplicate of http://stackoverflow.com/questions/7083693/detect-if-page-has-finished-loading – dpanshu Aug 05 '15 at 05:47

1 Answers1

0

jQuery provides functions such as
on('ready') - which is called when the DOM is ready to be manipulated.
load - which is called when all contents are finished loading.

you can use something like below:

jQuery(window).load(function () {
    mapsResume();

});
dpanshu
  • 443
  • 2
  • 14