0
我加載谷歌地圖API,並與callback
參數進行初始化函數initMap()
:當Google地圖+其他庫滿載時調用函數?
<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxx&callback=initMap"></script>
我想,以創建一個自定義標記(與CSS樣式),以使用其他腳本(js-rich-marker
)。
我加載:
script async="" defer="" src="https://raw.githubusercontent.com/googlemaps/js-rich-marker/gh-pages/src/richmarker-compiled.js"></script>
但initMap();
不會在頁面加載工作:
ReferenceError: Can't find variable: RichMarker
(我知道該腳本可以工作,因爲我可以更新與該更新菜單地圖與AJAX地圖,在這種情況下,它的工作。)。
我想這是因爲init函數在js-rich-marker
完全加載之前執行。
我已經嘗試調用init函數,當一切都加載,但它仍然不好。
document.addEventListener("DOMContentLoaded", function(event){
initMap();
});
$(window).load(function() {
initMap();
});
$(window).bind("load", function() {
// code goes here
});
我該如何調用一個函數一切都被加載?
'window.onload'是solution'。更多信息在這裏:http://stackoverflow.com/questions/588040/window-onload-vs-document-onload –