javascript - pass variable through initialize function inside addDomListener method -


google maps v3 api suggest loading initialize function using adddomlistener() method instead of attaching body tag.

<script>   function initialize() {     // map initialization   }   google.maps.event.adddomlistener(window, 'load', initialize); </script> not: <body onload="initialize()"> 

but, pass variable through initialize function: f.e. initialize(37). works using body onload method, not via adddomlistener method.

here's question: can using adddomlistener method. put simpler, following doesn't work, how can make work?

<script>     function initialize(countryid) {         // map initialization         // stuff countryid     }    google.maps.event.adddomlistener(window, 'load', initialize(37)); </script> 

use anonymous function:

google.maps.event.adddomlistener(window, 'load', function(){initialize(37);}); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -