Detecting user’s installed version of the Silverlight plug-in

Microsoft’s Silverlight plugin is finding its way to more and more high profile websites.  NBC used it to broadcast the Beijing Olympics and major sport sites are using to show live games and highlights.  (I should note that Silverlight is capable of much more than video playback, but that’s primarily what we’ve seen it used for recently.)

The JavaScript code which Microsoft provides to help with plug-in detection and rendering is, while helpful, not entirely complete.  For example, it currently lack a means of detecting the installed version.  This could be useful for tracking plugin penetration among your users, etc.  Here’s a simple script for detecting which, if any version of Silverlight is installed on a visitor’s computer.

var SilverlightVersion = "";

try { // SL version detection for Internet Explorer
	var control = new ActiveXObject('AgControl.AgControl');
	if (control.IsVersionSupported("1.0")){ SilverlightVersion = "1"; }
	if (control.IsVersionSupported("2.0")){ SilverlightVersion = "2"; }
	control = null;
catch (e) { // SL version detection for non-IE browsers
	var plugin = navigator.plugins["Silverlight Plug-In"] ;
	if (plugin){ SilverlightVersion = plugin.description.substring(0,1);	}

if (SilverlightVersion !== ""){
	document.write("Your browser supports Silverlight version: " + SilverlightVersion);
else {
	document.write("You do not have Silverlight installed.");