4.6. The Browser Object

ASP.NET has extensive information about various browsers. It provides a whole system for analyzing headers sent in by a browser and producing a complex Browser object that you can use from the page to tailor the application for the user. The control adapter architecture is based on this configuration system being able to specify where custom renderings should be used for particular browsers.

The AJAX Library specifies some basic browser definitions and determines which one is being used. JavaScript code can then easily check the browser object and draw conclusions about any unique requirements of the browser.

Listing 4-25 displays the information currently stored in the Browser object. It also shows how you can use an indexer to set custom properties on the Browser object. Remember that you can do this for any object in JavaScript. This is a case where extensibility is easy and intuitive.

Example 4-25. Working with the Browser object
<%@ Page Language="C#" Debug="true" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Browser object</title> <script type="text/javascript"> function pageLoad(sender, args) { Sys.Debug.trace("name = " + Sys.Browser.name); Sys.Debug.trace("version = " + Sys.Browser.version.toString()); Sys.Debug.trace("hasDebuggerStatement = " + Sys.Browser.hasDebuggerStatement.toString()); if(Sys.Browser.agent === Sys.Browser.InternetExplorer) { Sys.Debug.trace("agent = Sys.Browser.InternetExplorer"); } else if(Sys.Browser.agent ...

Get Professional ASP.NET 3.5 AJAX 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.