Version detection with Silverlight
Asked Answered
C

6

11

How can I efficiently and effectively detect the version and, for that matter, any available information about the instance of Silverlight currently running on the browser?

Capps answered 21/8, 2008 at 18:30 Comment(0)
B
7

The Silverlight control only has an IsVersionSupported function, which returns true / false when you give it a version number, e.g.:

if(slPlugin.isVersionSupported("2.0")) {
  alert("I haz some flavour of Silverlight 2");

You can be as specific as you want when checking the build, since the version string can include all of the following:

  • major - the major number
  • minor - the minor number
  • build - the build number
  • revision - the revision number

So we can check for a specific build number as follows:

if(slPlugin.isVersionSupported("2.0.30523")) {
  alert("I haz Silverlight 2.0.30523, but could be any revision.");

Silverlight 1.0 Beta included a control.settings.version property, which was replaced with the isVersionSupported() method. The idea is that you shouldn't be programming against specific versions of Silverlight. Rather, you should be checking if the client has at least verion 1.0, or 2.0, etc.

That being said, you can get the Silverlight version number in Firefox by checking the Silverlight plugin description:

alert(navigator.plugins["Silverlight Plug-In"].description);

Shows '2.0.30523.8' on my computer.

Note that it is possible to brute force it by iterating through all released version numbers. Presumably that's what BrowserHawk does - they'll report which version of Silverlight the client has installed.

Bulletin answered 25/8, 2008 at 21:31 Comment(0)
J
2

I got this from http://forums.asp.net/p/1135746/1997617.aspx#1997617 which is the same link Stu gave you. I just included the code snippet.

Silverlight.isInstalled = function(d)
{
    var c = false, a = null;
    try
    {
        var b = null;
        if(Silverlight.ua.Browser == "MSIE")
            b = new ActiveXObject("AgControl.AgControl");
        else
            if(navigator.plugins["Silverlight Plug-In"])
            {
                a = document.createElement("div");
                document.body.appendChild(a);
                a.innerHTML = '<embed type="application/x-silverlight" />';
                b = a.childNodes[0]
            }

        if(b.IsVersionSupported(d))
            c = true;
        b = null;
        Silverlight.available = true
    }
    catch(e)
    {
        c=false
    }

    if(a)
        document.body.removeChild(a);
    return c
};
Jemena answered 21/8, 2008 at 18:42 Comment(0)
T
2

found this site that detects the full version of silverlight- silverlight version (aka silverlightversion.com)

Tungting answered 22/9, 2009 at 15:24 Comment(1)
just fyi, this solution actually finds the exact version number of the installed plugin.Tungting
B
1

As mentioned in the above comments there is currently no efficient direct way to get the installed Silverlight version number (that works cross browser platform).

I wrote a post on how to workaround this problem and detect the Silverlight major version number (including version 3) programmatically and more efficiently using JavaScript.

You can find the code and the post at:

http://www.apijunkie.com/APIJunkie/blog/post/2009/04/How-to-programmatically-detect-Silverlight-version.aspx

Good luck!

Burglar answered 26/4, 2009 at 9:48 Comment(0)
P
1

Environment.Version will do what you want! Supported since Silverlight 2.0

Pinochle answered 4/7, 2012 at 15:21 Comment(0)
R
0

Look in silverlight.js:

http://forums.asp.net/p/1135746/1997617.aspx#1997617

Raki answered 21/8, 2008 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.