Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

browser - Version detection with Silverlight

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...