GetBrowser Method (.NET)

 

Returns: An immutable BrowserObj instance containing basic property values for the associated browser. This is a static method.

 

Syntax:

 BrowserObj browObj = BrowserObj.GetBrowser();

 BrowserObj browObj = BrowserObj.GetBrowser(string userAgent);

 

The GetBrowser method is one of the most fundamental methods in BrowserHawk. It is used to obtain an instance of the BrowserObj class which represents the basic browser capabilities for a particular browser.

 

When used within the context of an ASP.NET page, the GetBrowser() method signature should be used. BrowserHawk will obtain the user agent string automatically from the HttpContext associated with the current visitor.

 

When used outside the context of an ASP.NET page, it is necessary to explicitly pass in the user agent for the browser you wish to obtain capabilities for using the GetBrowser(string userAgent) method signature, since no HttpContext is available otherwise for BrowserHawk to obtain a user agent from.

 

C# Example 1 – Detecting browser capabilities of current site visitor:

<html>Your browser is:

<% BrowserObj browObj = BrowserObj.GetBrowser();

Response.Write(browObj.Browser + " " + browObj.Fullversion);

%>

</html>

 

C# Example 2 – Detecting browser capabilities for a specific user agent string:

<html>Browser for specified user agent is:

<% BrowserObj browObj = BrowserObj.GetBrowser("Mozilla/6.0 (WinXP; I)");

Response.Write(browObj.Browser + " " + browObj.Fullversion);

%>

</html>

 

Note: Basic property information is exposed through the BrowserObj class. For extended property information, such as disabled settings, plug-ins, connection speed, and screen size, see the ExtendedBrowserObj class.

 

See Also:

About the BrowserObj class (.NET)

About the ExtendedBrowserObj class (.NET)