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
descriptionmember 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;i0)
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
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
Interested in an performant, easy to extend, fully themeable
Silverlight / WPF charting library? Give the
free version of
Visiblox a try!