C# Tutorials and offshore development in India

Tutorials Resources Forum Reviews Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...





Javascript to detect if Silverlight is installed



This code sample shows how to use Javascript to determine if Silverlight is installed on the client browser.



The current versions of Internet Explorer consider Silverlight as a kind of ActiveX control. So, in order to determine if Silverlight is installed, we can attempt to create this ActiveX control using Javascript. If it fails to create the ActiveX control, we can assume that Silverlight is not installed.

For other browsers like Google Chrome, Netscape, FireFox, Safari etc, this can be determined by looking in to the Plugin array of the navigator object. The Silverlight plugin is installed with the name 'Silverlight Plug-In'.

The below sample code shows how to find if Silverlight is installed on the client browser or not.


<script language="javascript">
var browser = navigator.appName; // Get browser
var silverlightInstalled = false;

if (browser == 'Microsoft Internet Explorer')
{
try
{
var slControl = new ActiveXObject('AgControl.AgControl');
silverlightInstalled = true;
}
catch (e)
{
// Error. Silverlight not installed.
}
}
else
{
// Handle Netscape, FireFox, Google chrome etc
try
{
if (navigator.plugins["Silverlight Plug-In"])
{
silverlightInstalled = true;
}
}
catch (e)
{
// Error. Silverlight not installed.
}
}

alert(silverlightInstalled);
</script>



  • Previous Chapter: How to set a background image for your Sivlerlight control

  • Tutorial Index




  • About Us    Contact Us    Privacy Policy    Terms Of Use