Google Maps API V3 窗口加载事件监听器在某些浏览器中不起作用
一个奇怪的行为: 关于地图内事件的文档的最后部分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,但 确实... 有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论