1. Check whether the client has installed the Silverlight plug-in.
<SCRIPT type = "text/JavaScript">
Function checksilverlightinstalled ()
{
VaR issilverlightinstalled = false;
Try {
Try {
VaR slcontrol = new activexobject ('agcontrol. agcontrol'); // check IE
Issilverlightinstalled = true;
}
Catch (e ){
If (navigator. plugins ["Silverlight plug-in"]) // check for non-ie
{
Issilverlightinstalled = true;
}
}
}
Catch (e ){}
Return issilverlightinstalled;
}
Alert ("is the Silverlight plug-in installed? "+ Checksilverlightinstalled ())
</SCRIPT>
<SCRIPT type = "text/JavaScript">
Function checksilverlightinstalled ()
{
VaR issilverlightinstalled = false;
Try {
Try {
VaR slcontrol = new activexobject ('agcontrol. agcontrol'); // check IE
Issilverlightinstalled = true;
}
Catch (e ){
If (navigator. plugins ["Silverlight plug-in"]) // check for non-ie
{
Issilverlightinstalled = true;
}
}
}
Catch (e ){}
Return issilverlightinstalled;
}
Alert ("is the Silverlight plug-in installed? "+ Checksilverlightinstalled ())
</SCRIPT>
2. js checks whether IE is installed or supports Silverlight! (Only Ie can be detected)
JS checks whether IE is installed or supports Silverlight!
In JS, you can use the try and catch language names to determine whether the client has installed the Silverlight plug-in, and use the isversionsupported method of the plug-in to determine whether the client currently supports the specified version of Silverlight. Program !
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 ();
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 ();
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 ();
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 ();
Return C;
}
Alert (validsilverlight ("1.0 "));
// --> </MCE: SCRIPT>
The Silverlight control in ASP. NET uses this check. If you use this control, you can directly use the method "Silverlight. isinstalled (Version)" to call it!