Silverlight: Embedding on a Page Using the <object> Tag

Overview

Microsoft recommends using the <object> tag method of embedding a Silverlight application on a web page. This method works in all browsers supported by Silverlight and does not require JavaScript to be enabled. It also provides an easy way to provide fallback content if Silverlight isn't installed.

You can also use the JavaScript method and helper files if you need greater control over the embedding or install/upgrade process.

Using the <object> Tag

The following example shows the minimum code required to embed the Silverlight plug-in on a web page using the HTML <object> tag.

In most cases, you will want to add additional parameters and HTML elements to provide a complete user experience with increased cross browser support. A more complete sample can be seen at the end of this page.

Parameters

Below is a list of available parameters that can be passed to the plug-in using the <param> tag.

Parameter Description Type
allowHtmlPopupWindow Specifies whether the HtmlPage.PopupWindow method is allowed. Defaults to true for applications in the same domain, otherwise false. Boolean
autoUpgrade Specifies whether the plug-in should attempt to upgrade if minRuntimeVersion is newer than the current Silverlight version. Boolean
background Plug-in background color. Default is null (white). Color with or without alpha (RGB, ScRGB)
enablehtmlaccess Specifies whether the plug-in has full access to the browser DOM. Defaults to true for applications in the same domain, otherwise false. Boolean
initparams User-defined string of parameters. String or comma separated string (SL 1.0), comma separated key=value pairs (SL 2)
maxframerate Specifies the maximum number of frames per second that the plug-in can render. The default is 60. Integer
minRuntimeVersion Specifies the earliest version of the Silverlight plug-in required. Version number
onerror Error handler for parse and native code run-time errors. JavaScript function name
onfullscreenchanged Function to call when the FullScreen property changes. JavaScript function name
onload Function to call when the plug-in has finished loading in the DOM. JavaScript function name
onresize Function to call when the plug-in size changes. JavaScript function name
onsourcedownloadcomplete Function to call when the source download has completed. JavaScript function name
onsourcedownloadprogresschanged Function to call when the source download progress changes. JavaScript function name
source Specifies the address or relative path of either an initial XAML file or XAP. URI
splashscreensource Specifies a XAML page to use as the splash screen. URI
windowless Specifies the rendering mode for the plug-in for Windows versions of Silverlight. The default is false. Boolean

Example

The following example shows a full web page that embeds the Silverlight plug-in and runs a very simple application. It highlights providing basic alternate content when Silverlight isn't installed and also a workaround to prevent Safari from caching the page.

View Sample

Further Reading

Related information on the web is listed below.

Yahoo Forum Discussions