0

以下代码在所有版本的现代浏览器中将谷歌地图从内联 div 加载到颜色框弹出窗口,但无法在 ie7 等过时浏览器中加载地图。

<head>
<script src="http://maps.googleapis.com/maps/api/js?key=/////////;sensor=false"></script>
<script>
var myCenter=new google.maps.LatLng(xxxxxxxx,yyyyyyy);

function initialize()
{
var mapProp = {
  center:new google.maps.LatLng(xxxxxxxx,yyyyyyy),
    zoom:10,
  mapTypeId: google.maps.MapTypeId.ROADMAP
  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker=new google.maps.Marker({
  position:myCenter,
  });

marker.setMap(map);

var infowindow = new google.maps.InfoWindow({
  content:"hello world
  });

infowindow.open(map,marker);
}
//google.maps.event.addDomListener(window, 'load', initialize);
</script>

<script type="text/javascript">
jQuery(document).ready(function($){
$(".inline").colorbox({
  inline:true,
  href:"#googleMap",
  fixed:true,
  onComplete: function(){
     initialize();

  }
    });
});
</script>

</head>

<body>
<div style="display:none;">
<div id="googleMap" style="width:600px;height:500px;">
</div>
</div>

<a class='inline' href="#googleMap">Google Map</a>
</body>

我指出了 ie7 控制台在以下代码块中究竟是如何以及在何处注意到 js 错误的:

var marker=new google.maps.Marker({
  position:myCenter,
  .....*Error:Expected identifier, string or number...});

jQuery(document).ready(function($){
$(".inline").colorbox({
  inline:true,
  href:"#googleMap",
  fixed:true,
  onComplete: function(){
    ........*Error:Object expected...... initialize();

  }
    });
});

知道为什么会发生以及如何解决吗?

谢谢,

4

2 回答 2

1

我的建议是不要使用 inline 属性(旧的 IE 难以在 DOM 中移动某些类型的内容),而是尝试使用 html 属性。然后使用 onComplete 来初始化你的脚本:

$(".inline").colorbox({
  html:$('#googleMap').clone().attr('id', 'popupMap'),
  fixed:true,
  onComplete: initialize
});

您需要编辑initialize() 以定位#popupMap 而不是#googleMap。另一种选择是将它放在 iframe 中。

于 2013-02-23T10:06:58.983 回答
0

IE 对对象文字很挑剔。尝试删除逗号:

var marker=new google.maps.Marker({
    position:myCenter,
             //here  ^

Alsp,您在这里缺少双引号:

var infowindow = new google.maps.InfoWindow({
    content:"hello world

应该

content:"hello world"
于 2013-02-22T14:24:40.487 回答