I have the following code:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(53.743317, -0.331004),
zoom: 12
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?key={APIKEY}&sensor=false&callback=initialize';
document.body.appendChild(script);
}
If I put
$( window ).load(function() {
loadScript;
});
It won't load my map. Error in google maps js is Uncaught TypeError: Object #<Object> has no method 'Load'. However if I use
window.onload = loadScript;
It will load it in fine. I have absolutely no idea why.
$(window).load(loadScript());
Also works, just having it as a function that calls it doesn't. Could you tell me the reason of this behavior?
$( window ).load(function() { loadScript(); });doesn't work either