检测客户端是否安装 Silverlight 插件和判断IE是否安装或支持Silverlight(限IE)
Posted on 2010-01-11 22:05 WPF外包团队 — 长年承接WPF项目外包与WP8应用外包 阅读(1795) 评论(0) 编辑 收藏 举报1、检测客户端是否安装 Silverlight 插件
<script type="text/javascript">
function CheckSilverlightInstalled()
{
var isSilverlightInstalled = false;
try{
try{
var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE
isSilverlightInstalled = true;
}
catch(e){
if(navigator.plugins["Silverlight Plug-In"]) //检查非IE
{
isSilverlightInstalled = true;
}
}
}
catch(e){}
return isSilverlightInstalled;
}
alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())
</script>
<script type="text/javascript">
function CheckSilverlightInstalled()
{
var isSilverlightInstalled = false;
try{
try{
var slControl = new ActiveXObject('AgControl.AgControl'); //检查IE
isSilverlightInstalled = true;
}
catch(e){
if(navigator.plugins["Silverlight Plug-In"]) //检查非IE
{
isSilverlightInstalled = true;
}
}
}
catch(e){}
return isSilverlightInstalled;
}
alert("是否安装了 Silverlight 插件?" + CheckSilverlightInstalled())
</script>
2、JS判断IE是否安装或支持Silverlight!(只能检测IE)
JS判断IE是否安装或支持Silverlight!
JS中可以使用try,catch语名判断客户端是否安装了Silverlight插件,使用插件的IsVersionSupported方法判断目前客户端是否支持指定版本的Silverlight程序!
view plaincopy to clipboardprint?
<mce:script language="javascript"><!--
function validSilverlight(d)
{
var c=false,a=null;
try
{
var b=null;
var v=window.navigator.userAgent;
if(v.indexOf("MSIE")>-1)
{
b=new ActiveXObject("AgControl.AgControl");
}
else if(navigator.plugins["Silverlight Plug-In"])
{
a=document.createElement("div");
document.body.appendChild(a);
if(v.indexOf("Safari")>-1)
a.innerHTML='<embed type="application/x-silverlight" />';
else a.innerHTML='<object type="application/x-silverlight" data="data:," />';
b=a.childNodes[0]
}
//document.body.innerHTML;
if(b.IsVersionSupported(d))c=true;
b=null;
}catch(e)
{
c=false
}
if(a)document.body.removeChild(a);
return c;
}
alert(validSilverlight("1.0"));
// --></mce:script>
<mce:script language="javascript"><!--
function validSilverlight(d)
{
var c=false,a=null;
try
{
var b=null;
var v=window.navigator.userAgent;
if(v.indexOf("MSIE")>-1)
{
b=new ActiveXObject("AgControl.AgControl");
}
else if(navigator.plugins["Silverlight Plug-In"])
{
a=document.createElement("div");
document.body.appendChild(a);
if(v.indexOf("Safari")>-1)
a.innerHTML='<embed type="application/x-silverlight" />';
else a.innerHTML='<object type="application/x-silverlight" data="data:," />';
b=a.childNodes[0]
}
//document.body.innerHTML;
if(b.IsVersionSupported(d))c=true;
b=null;
}catch(e)
{
c=false
}
if(a)document.body.removeChild(a);
return c;
}
alert(validSilverlight("1.0"));
// --></mce:script>
由于ASP.NET 中的 Silverlight控件使用了这种检测,所以如果您使用了此控件就可以直接使用方法“Silverlight.isInstalled(version)”调用了!