Tutorials » Silverlight tutorials »

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 Silverlight control
More Chapters: Silverlight Tutorials
More Tutorials: Tutorial Index



Top Contributors
TodayLast 7 Daysmore...

Awards & Gifts

Online Members

VELIDIRAVIRAM
More...
 
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India