2012-06-13 78 views
1

我對IE8引發的一些錯誤感到困惑,但Firefox瀏覽器卻沒有。IE 8上的Javascript錯誤12

我看到了以下錯誤:

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] 
    ]; 

任何想法爲什麼這不起作用?任何致盲錯誤?

問候,

馬特

回答

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 
}); 
+0

謝謝,這刪除了錯誤。雖然沒有顯示。由於應用程序使用Javascript作爲登錄,所以Javascript尚未被禁用。 – MHibbin

1

ioseb已經發布了完美的答案。然而,爲了避免將來出現這樣的錯誤,我建議使用google閉包編譯器,它會在出現這種錯誤時提醒你。您在這裏:http://code.google.com/p/closure-compiler/downloads/list

+0

好的,謝謝我會看看這個。我仍然在學習,所以這會很有用。 – MHibbin

+0

這是你如何使用它:「java -jar sh/compiler.jar --js file1.js file2.js filex.js」。我們在jenkins中使用它,並且正在執行此操作:「java -jar sh/compiler.jar --js file1.js file2.js filex.js --warning_level QUIET>/dev/null」。這將抑制任何錯誤,但退出代碼退出!= 0,所以詹金斯失敗 – sdepold

+0

sdepold謝謝,我會看看在一些停機時間,目前沒有訪問我的nix機器。再次感謝。 – MHibbin