2008-08-21 36 views

回答

7

Silverlight控件只有一个IsVersionSupported function,当你给它一个版本号,返回真/假,如:

if(slPlugin.isVersionSupported("2.0")) { 
    alert("I haz some flavour of Silverlight 2"); 

你可以像你想检查构建时具体,由于版本字符串可以包括以下所有条件:

  • 大 - 各大数
  • 轻微 - 次要号码
  • 构建 - 内部版本号
  • 版本 - 版本号

因此,我们可以检查特定的版本号如下:

if(slPlugin.isVersionSupported("2.0.30523")) { 
    alert("I haz Silverlight 2.0.30523, but could be any revision."); 

Silverlight 1.0 Beta included a control.settings.version property, which was replaced with the isVersionSupported() method。这个想法是,你不应该针对特定版本的Silverlight进行编程。相反,你应该检查客户端是否有至少优化版本1.0或2.0,等

话虽这么说,你可以通过检查Silverlight插件的描述获得在Firefox中的Silverlight版本号:

alert(navigator.plugins["Silverlight Plug-In"].description); 

在我的电脑上显示“2.0.30523.8”。

请注意,可以通过重复遍历所有发布的版本号来蛮力。 Presumably that's what BrowserHawk does - 他们会报告客户端安装的Silverlight版本。

2

我得到这个从http://forums.asp.net/p/1135746/1997617.aspx#1997617这是相同的链接Stu给你。我只是包含了代码片段。

Silverlight.isInstalled = function(d) 
{ 
    var c = false, a = null; 
    try 
    { 
     var b = null; 
     if(Silverlight.ua.Browser == "MSIE") 
      b = new ActiveXObject("AgControl.AgControl"); 
     else 
      if(navigator.plugins["Silverlight Plug-In"]) 
      { 
       a = document.createElement("div"); 
       document.body.appendChild(a); 
       a.innerHTML = '<embed type="application/x-silverlight" />'; 
       b = a.childNodes[0] 
      } 

     if(b.IsVersionSupported(d)) 
      c = true; 
     b = null; 
     Silverlight.available = true 
    } 
    catch(e) 
    { 
     c=false 
    } 

    if(a) 
     document.body.removeChild(a); 
    return c 
}; 
2

发现这个网站检测的完整版本silverlight- silverlight version(又名silverlightversion.com)

+0

这个解决方案实际上找到了安装插件的确切版本号。 – 2011-02-07 15:17:26

1

环境。版本将做你想做的!自Silverlight 2.0以来支持