2011-04-12 95 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”

相关问题