The other day I wanted to find out what version of Silverlight is installed on my computer. This task is actually not as simple as it sounds as the Silverlight plugin is actually browser dependent: there’s a different one installed for Internet Explorer and a different for other browsers. The only way I’ve found to determine current Silverlight version is through Javascript.
Silverlight version detection: Internet Explorer
For Internet Explorer the ActiveXObject(“AgControl.AgControl”) has to be created. This object has and isVersionSupported(versionNumber) method which returns whether versionNumber is supported.
var AgControl = new ActiveXObject("AgControl.AgControl"); var version = "3.0.50106.0"; // The Silverlight version to test for if(AgControl == null) alert("Silverlight is not installed!"); else if AgControl.isVersionSupported(version) alert("Silverlight v" + version + " is supported."); else alert("Silverlight v" + version + " is not supported!");
Unfortunately it does not have a method that would return the current version thus to obtain the current version, version numbers have to be iterated. In my version detection script I’ve simply implemented a binary search that loops through the parts of the version numbers (major, minor, build and revision versions) determining the greatest version that is still supported. Not a very nice solution but the AgControl object leaves no other choice!
Silverlight version detection: other browsers (Firefox, Google Chrome, Safari etc)
For other browsers getting the Silverlight version is quite simple. The navigator.plugins["Silverlight Plug-In"] object contains information on the Silverlight plugin. It has the description member variable which contains the Silverlight version. This class makes version detection really simple compared to the hassle one has to go through with Internet Explorer!
var nav = navigator.plugins["Silverlight Plug-In"]; if(nav == null) alert("Silverlight is not installed!"); else alert("Silverlight version " + nav.description + " is installed.");
Silverlight version detection script
I have created a function that returns the current Silverlight version or -1 if Silverlight is not installed. This script is just a mixture of the Internet Explorer version detection part (with the binary version search implemented) and the other browsers detection script.
See this version detection script in action:
You can use the script the following way:
var slVersion = GetSilverlightVersion(); if(slVersion != -1) document.writeln("Your Silverlight version is: <strong>" +slVersion + "</strong>" ); else document.writeln("<strong>Your do not have Silverlight installed on this computer</strong>");
You can download the Javascript file here: SilverlightVersion.js, or download a standalone HTML version (where the script is embedded within the HTML) here: SilverlightVersion.html.
You can also simply copy the script source code from here:




