2013-03-08 27 views
0

您好我有这样的代码在我的页脚,它workes在所有浏览器罚款,但IE8在IE8只直接pageloads借机罚款,如果我输入域和回车键,它就像一个魅力,但如果我刷新,我得到一个“对象expekted”,因为“google.maps”成为一个空的对象,例如:JSON.stringify(google.maps)=='[]'脚本仅适用第一次,在IE8刷新后不

任何ide应该是错的? (如果我删除缓存,然后转到页直接它仍然能正常工作。)

<script type='text/javascript' src='http://www.google.com/jsapi?ver=3.2.1'></script> 
<script type="text/javascript"> 
google.setOnLoadCallback(function(){ 
     jQuery(".all-map").each(function(index) { 
     var obj = jQuery.parseJSON(jQuery(this).val()); 
     var allMap = new google.maps.Map(document.getElementById(obj.mapId), { 
     zoom: obj.zoom, 
     center: new google.maps.LatLng(obj.centerLat, obj.centerLong), 
     mapTypeId: google.maps.MapTypeId.SATELLITE 
     } 
     ); 

     var locations = eval(obj.locations); 
    var infowindow = new google.maps.InfoWindow(); 
    var marker, i; 
    for (i = 0; i < locations.length; i++) { 
     marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: allMap 
     }); 
    google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      jQuery('#'+obj.mapId).parent().siblings().eq(i).click(); 
      infowindow.setContent(locations[i][0]); 
      infowindow.open(allMap, marker); 
     } 
     })(marker, i)); 
    } 

    }); 

}); 
</script> 
+0

我想说的IE8被打破。是所有版本的IE还是只有IE8都一样?您是否尝试过IE中的不同兼容性设置?什么是页面的缓存设置? – 2013-03-08 15:11:25

+0

确实的document.getElementById(obj.mapId)页面流存在此脚本之前还是之后?只是认为onload回调可能在对象存在之前触发。 – 2013-03-08 15:22:40

+0

同样在所有comp模式中,不知道缓存设置,但它是全新安装 刷新后“google.maps”为空的问题 – 2013-03-08 15:24:20

回答

0

这是一个竞争条件。当信息已经存在于IE的缓存中时,google onload事件处理程序在DOM呈现(页面onload事件)之前运行并且地图对象不存在于DOM中,因此document.getDocumentById找不到它。您需要等待文档加载以及google脚本onload事件触发。

+0

'jQuery(function(){ google.setOnLoadCallback(function(){ console.log(JSON。 stringify(google.maps)); }); ); ' 仍在重新加载时输出“[]”,但第一次包含大量信息。 我需要等更长时间吗? – 2013-03-08 19:35:11

0

我仍然不知道发生了什么事,但我做了一些调整和了when与

$(document).ready(function() { 
    google.load("maps", "3", { 
     callback: initialize , 
     other_params: "sensor=false" 
    }); 
}); 

,现在,它在IE8的作品,以及,4帮助的感谢!

相关问题