1

奇妙な動作:マップ API 内のイベントに関するドキュメントの最後の部分には、次のように書かれています。

>  If you've been reading the documentation this far, you're probably
> already familiar with one DOM event: the window.onload event, which
> we've handled within the <body> tag. We use this event to trigger the
> initial Javascript code once an HTML page is fully loaded, as shown
> below: <script>   function initialize() {
> 
>     // Map initialization
> 
>   } </script> <body onload="initialize()">   <div
> id="map_canvas"></div> </body> Although this event is attached to the
> <body> element here, this event is really a window event indicating
> that the DOM hierarchy below the window element has been fully built
> out and rendered. Although easy to understand, having an onload event
> within a <body> tag mixes content with behavior. Generally, it is good
> practice to separate your content code (HTML) from your behavioral
> code (Javascript) and provide your presentation code (CSS) separately
> as well. You can do so by replacing the inline onload event handler
> with a DOM listener within your Maps API Javascript code like so:
> <script>   function initialize() {
> 
>     // Map initialization
> 
>   }
>      google.maps.event.addDomListener(window, 'load', initialize);
> </script> <body>   <div id="map_canvas"></div> </body>

何とかgoogle.maps.event.addDomListener(window, 'load', initialize);Firefox/Safari では動作しませんが、 <body onload="initialize()">動作します...理由はありますか?

4

0 に答える 0