lazy load google maps api v3 jQuery callback

前端 未结 2 1410
闹比i
闹比i 2020-12-29 11:18

I do lazy loading of the google maps api v3 javascript

The documentation says about putting as a callback parameter in the url the name of the function, which will b

相关标签:
2条回答
  • 2020-12-29 11:31

    Because the callback must be global, you could make one by accessing window from within the ready handler.

    $(document).ready(function(){
       var s = document.createElement("script");
       s.type = "text/javascript";
       s.src  = "http://maps.google.com/maps/api/js?v=3&sensor=true&callback=gmap_draw";
       window.gmap_draw = function(){
           alert ("Callback code here");
       };
       $("head").append(s);  
    });
    
    0 讨论(0)
  • 2020-12-29 11:50

    Another option is to use Google Loader:

    $.getScript('https://www.google.com/jsapi', function()
    {
        google.load('maps', '3', { other_params: 'sensor=false', callback: function()
        {
            // Callback code here
        }});
    });
    
    0 讨论(0)
提交回复
热议问题