IE 8上的Javascript错误

时间:2012-06-13 09:01:45

标签: javascript google-maps-api-3 internet-explorer-8

我对Internet Explorer 8引发的一些错误感到困惑,而不是Firefox。

我看到以下错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windwos NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Wed, 13 Jun 2012 08:33:22 UTC

Message: Object expected
Line: 3
Char: 1
Code: 0
URI: http://<ipAddress>/.../locations.js

Message: Syntax error
Line: 34
Char: 11
Code: 0
URI: http://<ipAddress>/.../testMap1.html

我正在使用以下文件......

testMap1.html:

    <div id="map_canvas" style="width: 1200px; height: 700px;">map div foo</div>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="/static/app/foo/locations.js"></script>
    <!--<script type="text/javascript" src="/static/app/foo/script.js"></script>-->
    <script type="text/javascript">

  var centerPoint = new google.maps.LatLng(9.449062,7.950439);

  var parliament = new google.maps.LatLng(9.449062,7.950439);
  var parliament1 = new google.maps.LatLng(34.449062,7.950439);
  var marker;
  var map;
  var i;

  function initialize() {
      var mapOptions = {
        zoom: 2,
        mapTypeId: google.maps.MapTypeId.HYBRID,
        center: centerPoint
      };

      map = new google.maps.Map(document.getElementById("map_canvas"),
              mapOptions);


      for (i = 0; i < locations.length; i++) {
          marker = new google.maps.Marker({
            map:map,
            draggable: false,
            animation: google.maps.Animation.DROP,
            position: new google.maps.LatLng(locations[i][0], locations[i][1]),
          });
          google.maps.event.addListener(marker, 'click', toggleBounce);
      }
  }

// for toggleBounce, need to add ", toggleBounce" back into previous brackets.

  function toggleBounce() {

      if (marker.getAnimation() != null) {
        marker.setAnimation(null);
      } else {
      marker.setAnimation(google.maps.Animation.BOUNCE);
      }

  }
    </script>

locations.js:

  var locations = [
     [9.449062, 7.950439, 0],
     [34.449062, 10.950439, 50]
  ];

为什么这不起作用的任何想法?任何致盲错误?

此致

马特

2 个答案:

答案 0 :(得分:4)

从此行删除尾随逗号:

position: new google.maps.LatLng(locations[i][0], locations[i][1]),

它会导致IE出现问题。

marker = new google.maps.Marker({
   map:map,
   draggable: false,
   animation: google.maps.Animation.DROP,
   position: new google.maps.LatLng(locations[i][0], locations[i][1]) //removed comma
});

答案 1 :(得分:1)

ioseb已经发布了完美答案。但是,为了防止将来出现此类错误,我建议使用谷歌闭包编译器,如果发生此类错误,它会发出警告。您的位置是:http://code.google.com/p/closure-compiler/downloads/list