O'Reilly logo

Professional Silverlight® 4 by Bill Evjen, Jason Beres, Devin Rader

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required