开发者

Google Maps API V3 window load eventListener not working in some browsers

A strange behaviour: The last part of the Documentation on events inside maps API says that

>  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>

Somehow google.maps.event.addDomListener(window, 'load', initialize); doesn't work for Firefox/Safari, but <body onload="initialize()"> does... Any ideas why?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜