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:
function GetSilverlightVersion(){ var parts = Array("ver-major", "ver-minor", "ver-build", "ver-revision"); var nav = navigator.plugins["Silverlight Plug-In"]; var versionStr = ""; // Non IE-browsers if (nav) { versionStr = nav.description; } // IE-browsers else { if(SilverlightIsInstalledOnIE) versionStr = GetSilverlightVersionOnIE(); else versionStr = -1; } return versionStr; } function SilverlightIsInstalledOnIE(version) { if(version == null) version = "1.0"; var AgControl = new ActiveXObject("AgControl.AgControl"); if(AgControl == null) return false; else return AgControl.isVersionSupported(version); } function GetSilverlightVersionOnIE() { var currVersion = Array(1,0,0,0); for(var i=0;i<currVersion.length;i++){ currVersion[i] = FindSupportedMaxVersionOnIE(currVersion, i,0,10000000); } return GetVersionString(currVersion); } function GetVersionString(versionArr,currVersion,index) { if(index == null) index = -1; var versionStr = ""; for(var i=0;i<versionArr.length;i++){ if(i>0) versionStr += "."; if(i==index) versionStr +=currVersion; else versionStr += versionArr[i]; } return versionStr; } function FindSupportedMaxVersionOnIE(versionArr, index,bottom,top) { if(bottom >= top){ return bottom; } var currVersion = bottom; var prevVersion = currVersion; var step = 1; while(currVersion<top) { if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,currVersion,index))) { prevVersion = currVersion; currVersion += step; step *= 2; } else return FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,currVersion-1) } if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,top,index))) return top; else return FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,top-1) }
What the version number means
The version number consists of four parts: [Major version].[Minor version].[Build version].[Revision version]. So version 3.0.50106.0 means Silverlight v3.0, build 50106.
Up to Silverlight 4 about 20 different versions have been released. Interesting enough Microsoft has only released one version where the minor version number was not 0, this was the Silverlight 2 pre-release, which ran under version 1.1.20926.0. For the complete version release list see the Silverlight release history on Wikipedia. For details on what important changes each release contains download the official Microsoft Silverlight release history document.
Related article: Silverlight 4 beta released leaving Flex behind
Tags: Silverlight, Source code, Version



[...] actually works and what the Silverlight version numbers mean, read the post on my ScottLogic blog: Determining Silverlight Version Installed – source code & explanation var [...]
Hi Gergely,
You might find it useful to run your JavaScript through a tool called JSLint http://www.jslint.com/. It can be a bit picky but it’s an easy way of cleaning up the code.
Chris
p.s. It also looks like you’ve run into some encoding issues in the inline copy of the script.
Take a look at the source on silverlightversion.com, it accomplishes the same thing but the jscript is a bit more efficient.
Chris: you’re right, the JavaScript could be a bit more up to standards… but most of the recommendations on jslint.com were to use brackets for one line ifs and don’t use document.writeln
For now I’ll just leave it as is but thanks for the feedback!
Silverlight version: the source on silverilghtversion.com is shorter but actually is less effcient as it doesn’t use binary search to find the version number like this script does. Though the author was apparently aware of this I guess, hence the comment in the source:
“//the following would be faster with a binary search. Im kinda sleepy though.”
ah true, i glanced over and didnt notice this was a binary search… so yes, this is more efficient!