The last step of the Silverlight installer is to ask the user to restart or refresh their browser. This approach forces the browser to re-evaluate the page's Silverlight instantiation logic once the control is installed. In the case of non-IE browsers, the restart also forces the browser to refresh its cache of known controls.
To get started, we need several logical components:
For the first component we can use the commonly available setTimeout and setInterval methods. For the purposes of this post I will use setTimeout since it doesn't require us to explicitly cancel future executions. You should evaluate both methods and determine which works best for your scenario.
The second component is also rather easy. The Silverlight.js helper file, available in the Silverlight SDK, provides a method named isInstalled which answers this very question.
Finally, what action should the page take when it detects that Silverlight is installed? The simplest answer is to refresh itself. This will enable the default instantiation logic to render the Silverlight application without any additional modifications.
<title>Automatically Start Silverlight on Install</title>
WaitForInstallCompletion = function()
//This forces Firefox/Safari to refresh their
//list of known plugins.
//IE does not support the method, so an
//exception will be thrown.
if ( Silverlight.isInstalled("1.0") )
//Silverlight is installed. Refresh the page.
//Wait 3 seconds and try again
onLoad = function()
//This only works if we are performing a clean install,
//not an upgrade.
if ( !Silverlight.isInstalled("1.0") )
//Silverlight is not installed. Try to refresh
//the page when it is installed.
These references should be changed to point at the corresponding files in your web application
LimitationsThis approach is limited to new installations of Silverlight. Websites which require a newer version of Silverlight than what is already installed on the user's machine will still require a restart. Fortunately, Silverlight's automatic updater makes new version requirements a transient problem.
ConclusionThe Silverlight installation process provides a good user experience with minimal requirements for the web author. The script solution presented in this post builds on the default experience by helping websites take more control their end-to-end flow.