Chapter 13. DOM Interaction

WHAT'S IN THIS CHAPTER?

  • Configuring the Silverlight plug-in

  • Interacting with the plug-in using JavaScript

Because Silverlight is a browser plug-in, eventually you must embed the Silverlight player into a host web page. The browser sees the plug-in as any other ordinary object in the Document Object Model (DOM), and, therefore, you can use standard HTML and JavaScript DOM manipulation techniques to configure and interact with the plug-in. This chapter looks at the ways you can configure the plug-in in the browser and how you can use JavaScript to interact with the plug-in. It also looks at a feature of Silverlight called the HTML Bridge, which allows you to interoperate between JavaScript and managed code running in the plug-in.

CONFIGURING THE SILVERLIGHT PLUG-IN

When you set up a new web page to host a Silverlight application, you must add the appropriate HTML and JavaScript in order to load and configure the plug-in. If you created a new website when you created the Silverlight application, Visual Studio automatically generates both a test ASP.NET page and test HTML page. These pages include the HTML and JavaScript needed to embed the player.

If you add the Silverlight application to an existing site or page, you can also add this content manually by adding an <object> tag to your page, filling in all the appropriate object <param> tags, and including the appropriate JavaScript files and code. Listing 13-1 shows the contents of the test ASP.NET page.

Example 13-1. Embedding ...

Get Professional Silverlight® 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.