2011-04-12 98 views
0

這是JavaScript的一個共同的一塊用於顯示在Silverlight客戶閃屏:爲什麼在Firefox和Chrome中失敗?

function onSourceDownloadProgressChanged(sender, eventArgs) { 
      var myHost = document.getElementById("Xaml1"); 
      var rectBar = myHost.content.findName("rectBar"); 
      var rectBorder = myHost.content.findName("rectBorder"); 
      if (eventArgs.progress) 
       rectBar.Width = eventArgs.progress * rectBorder.Width; 
      else 
       rectBar.Width = eventArgs.get_progress() * rectBorder.Width; 
     } 

出於某種原因,Firefox和Chrome就在這行錯誤:

var rectBar = myHost.content.findName("rectBar"); 

他們抱怨說「myHost爲空」

這在Internet Explorer中正常工作,但在Firefox和Chrome中,進度條永遠不會因此錯誤而更新。

的關鍵部分是遍歷這個樣子的:

<div id="silverlightControlHost"> 
     <object id="xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> 
      <param name="source" value="ClientBin/MyApp.xap"/> 
      <param name="onError" value="onSilverlightError" /> 
      <param name="background" value="white" /> 
      <param name="minRuntimeVersion" value="4.0.50826.0" /> 
      <param name="autoUpgrade" value="true" /> 
      <param name="splashscreensource" value="ClientBin/SplashScreen.xaml" />  
      <param name="onSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" /> 
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none"> 
       <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/> 
      </a> 
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div> 

回答

4

因爲它是xaml1,而不是Xaml1,並且Internet Explorer太懶惰而無法關心您的輸入錯誤。

+0

好的。我很驚訝,我沒有選擇那個。 – 2011-04-12 20:01:51

+0

@NissanFan:爲了將來的參考,從這樣一個簡單的任務這樣的錯誤幾乎總是指向這樣的錯字。 :) – 2011-04-13 00:33:25

3

因爲其他瀏覽器是區分大小寫的。 「Xaml1」!=「xaml1」

相關問題