async loading javascript with [removed]

后端 未结 5 1006
野趣味
野趣味 2020-11-29 12:08

I am trying to async the google map api javascript.

So, the normal script tag works

5条回答
  •  萌比男神i
    2020-11-29 12:43

    Adding a comment here since I struggled a fair bit with this problem. When loading the script asynchronously (via a button click for example), make sure you follow the instructions exactly as on the site.

    I first got the document.write error when I didn't give the callback value. And after giving the callback, I got the window.initialize error because ... duh ... there was no initialize function in my code. I changed that to my function name (something like loadMap) and it started working.

    To be honest, just copy the code from the site and it should work. Replace window.onload with whatever you need to trigger the said function.

提交回复
热议问题