Google maps v3 api suggest loading the initialize function using the addDomListener() method instead of attaching it to the body tag.
<script>
function initialize() {
// Map initialization
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
not:
<body onload="initialize()">
But, I would like to pass a variable through the initialize function: f.e. initialize(37). This only works using the body onload method, not via the addDomListener method.
Here's my question: can I do this using the addDomListener method. To put it simpler, following doesn't work, how can I make it work?
<script>
function initialize(countryID) {
// Map initialization
// Do stuff with countryID
}
google.maps.event.addDomListener(window, 'load', initialize(37));
</script>
use a anonymous function:
google.maps.event.addDomListener(window, 'load', function(){initialize(37);});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With