Body.onload 关于页面加载完毕的问题

由于上午的Gmap没有调试成功,一直比较郁闷。
1、下午的时候收到K_Reverter的邮件他告诉我可以用window.onload=func的方法来代替Body.onload使用。
2、上网找了点资料,在360doc看到了一个老外关于window.onload的代码,也拿过来用下。
修改代码如下:

<script type=”text/javascript” src=”http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA43IALmfadaZgVb1L-IEizRRKyzQqj4F9myd02mWX0DutlkqY_BQi03TATJA59RMvJYUa4fN7lK7X5g”>
</script>

<div id=”map” style=”width: 600px; height: 400px;”></div>

<script type=”text/javascript”>
function init() {
if (GBrowserIsCompatible()) {
var map=new GMap(document.getElementById(“map”));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_TYPE);
map.centerAndZoom(new GPoint(121.5581,29.8394), 8);
// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = “http://www.google.com/mapfiles/shadow50.png”;
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

// Create a lettered icon for this point using our icon class
var letter = String.fromCharCode(“A”.charCodeAt(0) + 25);
var icon = new GIcon(baseIcon);
icon.image = “http://www.google.com/mapfiles/marker” + letter + “.png”;
var ningbo = new GMarker(new GPoint(121.5581,29.83941),icon);
GEvent.addListener(ningbo, “click”, function(){
ningbo.openInfoWindowHtml(“过几天出去溜达下!”); });
map.addOverlay(ningbo);

// Create a lettered icon for this point using our icon class
var letter = String.fromCharCode(“A”.charCodeAt(0) + 24);
var icon = new GIcon(baseIcon);
icon.image = “http://www.google.com/mapfiles/marker” + letter + “.png”;
var zhoushan = new GMarker(new GPoint(122.1018,30.0207),icon);
GEvent.addListener(zhoushan, “click”, function(){
zhoushan.openInfoWindowHtml(“你说什么啊?我听不见呀!”);
});
map.addOverlay(zhoushan);
}
};

/* for Mozilla */
if (document.addEventListener) {
document.addEventListener(“DOMContentLoaded”, init, null);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
init
/*@end @*/

/* for other browsers */
window.onload = init;
</script>

update:
1、加载比较慢,请耐心等待片刻,页面里有太多的脚本了,嘿嘿。看来玩Gmap还得有个自己的空间才是!
2、在2个GMarker之间点击的时候先打开的openInfoWindow不能自由关闭,看来还要继续除虫。

Tagged , .