Interacting with the DOM
When hosted in a browser, Silverlight is a part of the page, the same as any other HTML object in it, so it's only fair that Silverlight will be able to interact with the different elements on the page. Meet the System.Window.Browser
namespace. It will be your starting point for communicating with the HTML DOM. The namespace exposes different methods for accessing cookies and query strings, calling the JavaScript functions, and even manipulating the DOM elements.
Accessing cookies and query strings
We all know (and some of us love) HTML cookies, which are those little text nuggets that the browser saves on the user's computer and are mostly used for authentication, session tracking, and so on. Well, the good news is that you can access and save cookies using Silverlight as well.
Saving a cookie is a simple matter of calling the SetProperty
method of the HtmlPage
class's Document
object with a string in the following format:
Key=Value;expires=ExpireDate
The following...