简体   繁体   中英

Dojo : load cross domain script dynamically and synchronously

I'm working on a project where i have to use dojo (i'm doing a custom widget) and the google map api (v3)

For some technical reason, i have to include the google map api through my js file and not through my html file, so i can't use

<script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places'></script>

The load have to be done synchronously.

I've tried some things, first adding the script using

document.write("<script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places'></script>");

But that's not working, i get a blank page instead, using firebug i can see that the panel "Network" is clearing and the page make an infinite loading of google map api script.

I think i can't do it using dojo.io.script (which allow to make cross domain request), because we can't make synchronous request with dojo.io.script

Any help will be appreciated ;)

Well, solution was to use google map callback :

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&callback=mapLoaded";
document.body.appendChild(script);

Then make the function "mapLoaded" which execute the code

Thanks for those who taked time to answer me

You should still be able to use dojo.io.script. It does not have to be synchronous. The maps API takes ac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM