provide a consistent method for passing in parameters and take care of cross-browser differences in addition to providing
see Embedding using the
It is important to provide users who don't have Silverlight installed the best possible user experience. This includes providing the user with a preview of the content they will get in return for taking the time to install, keeping them within your page and automatically showing the Silverlight enabled content once the installation has completed. Unfortunately, currently all other browsers except Internet Explorer on Windows will require the user to restart their browser after installation. More details can be found in the Silverlight Installation Experience Guide provided by Microsoft.
An easy way to test the experience users without Silverlight will get is to use Internet Explorer 7's add-on manager to temporarily disable the Silverlight "Microsoft Silverlight" or "AgControl Class" add-on.
The two helper files Microsoft provides are
CreateSilverlight.js. The former is the main file you
will need, while the latter is an optional encapsulation of the settings that will be passed when the plug-in and application are created.
These files, including their localized versions, can be found in the Silverlight SDK Tools folder.
Silverlight.js is minified (8kB) and contains the code required to embed the Silverlight plug-in.
CreateSilverlight.js on the other hand
only contains a call-thru to
Silverlight.js with a set of parameters.
To embed a Silverlight application on a web page, you will need the following on your page:
<script>tag that references the
<div>tag, that will contain the Silverlight plug-in and thus the application.
<script>tag that contains code (usually
createObjectEx();) to render the plug-in.
<script>tag that references the
CreateSilverlight.js file essentially only contains one function, you may want to avoid using this file to minimize unnecessary
for additional tips.
Silverlight.js file creates a class named
Silverlight that provides methods and properties to create the application
on the page and also to help get information about the environment, such as whether Silverlight is installed and which browser is running.
The following table lists public properties and methods of the
||A property that returns a Boolean value indicating whether any version Silverlight has been installed.|
||Creates a Silverlight application with the given list of parameters.|
||Creates a Silverlight application with parameters given in a JSON dictionary.|
||A method that returns a Boolean value indicating whether the specified version of Silverlight has been installed.|
||A method that returns a Boolean value indicating whether the current operating system and browser combination is supported.|
||A property that gets a string representing the running browser. Values returned include
||A property that gets a string representing the running operating system. Values returned include
createObjectEx are the methods used to create the Silverlight application on a page. The
difference between the two methods is that
createObject takes parameters as method arguments in a predefined order and
createObjectEx takes a single JSON object with named key-value pairs. Thus
createObjectEx is less prone to typing errors and also provides
a cleaner way to use built-in default values.
The following table lists the required parameters.
||The source XAML file or ID of an inline XAML script block prefixed with #.|
||The HTML block element that will contain the application.|
||The HTML element ID for the newly created application.|
||A JSON object containing initialization properties, such as
||A JSON object containing global level event handlers
The detailed method signatures and full list of available parameters that can be set can be found in the Silverlight SDK documentation.
You can use the
Silverlight.isInstalled(version) method to check if the required version of Silverlight is installed on the client. This will allow
your site to provide additional information and sample content to users who haven't installed Silverlight yet or don't have the correct version.
The following example loads a Silverlight application from the
myApplication.xaml file in the MyApplication folder. If Silverlight isn't installed, it will
display a preview image and reattempt to display the application every three seconds until the installation has completed.
Related information on the web is listed below.