Differences in detecting Extended properties

 

The most significant difference between programming with the ActiveX Vs. .NET version of BrowserHawk is how extended properties are represented and tested.

Class differences

 

As you will recall, extended properties are those properties which can vary across the same browser type, version, and platform, depending on end user settings and preferences. For example, plug-ins, screen size, connection speed, and disabled Vs. enabled settings are all examples of extended properties.

 

In the ActiveX version of BrowserHawk, extended properties and basic properties are all combined in the same BrowserObj class. The ActiveX BrowserObj class includes all the basic properties, like Browser and Platform, as well as all the extended properties, like Plugin_Flash and ActiveXEnabled.

 

Conversely, in the .NET version of BrowserHawk, the basic and extended properties are represented by separate classes. In the .NET version, the BrowserObj class contains only the basic properties such as Browser, Platform, Version, Tables, SSL, etc. Then there is the ExtendedBrowserObj class which contains only the extended browser properties.

 

This new and improved object model found in the .NET version makes programming with BrowserHawk both more intuitive and efficient.

Coding differences

 

When using extended properties it is necessary to tell BrowserHawk exactly which extended properties you wish to test for. This helps keep the testing time and any overhead associated with the tests to an absolute minimum.

 

With the ActiveX version of BrowserHawk you set the extended properties to be checked by calling the SetExtProperties method. After calling SetExtProperties you then call the GetExtPropertiesEx method. This method is used to set various preferences and options related to the extended property testing, such as what requestType to use, what message (like "Please wait…") you want displayed during the test, and the background color to be displayed during the test.

 

Conversely with the .NET version, these two methods do not exist. Instead you create an instance of the ExtendedOptions class. You use the AddProperties method to tell BrowserHawk which extended properties you want to test for (taking the place of the call to SetExtProperties in the ActiveX version). You then use the other properties of this class such as PageMessage and BodyTag to set various preference and options (taking the place of the variable list of parameters passed in to GetExtPropertiesEx in the ActiveX version).

 

Once you have set the various properties and methods of the ExtendedOptions class as desired, you then call the static GetExtendedBrowser method of the BrowserObj class, passing in your ExtendedOptions class as a parameter. This programming statement causes the actual tests to take place, just as GetExtPropertiesEx does in the ActiveX version.

 

The call to GetExtendedBrowser returns an ExtendedBrowserObj class. You then use this class to access the returned test results.

 

For the first time reader, this can be a bit confusing. But when you look at the actual code involved, you'll see the approach followed in the .NET version is actually more intuitive and flexible, and will grasp these new concepts quickly.

An example to demonstrate these differences

 

To help you better understand the differences between extended property detection in the ActiveX Vs. .NET version, let's take a look at an example. For this example we wish to determine if the visitor is using IE, and whether they have JavaScript enabled and the Flash plug-in installed. If the visitor does not meet these criteria we will redirect them to another page.

 

Let's take a look at the code required to do this from both ASP with the ActiveX version, and ASP.NET with the .NET version.

 

Code sample for ASP with ActiveX version of BrowserHawk:

 

<%

set bhObj = Server.CreateObject("cyScape.BrowserObj")

bhObj.SetExtProperties("JavaScriptEnabled, Plugin_Flash")

bhObj.GetExtPropertiesEx 0, "BGCOLOR=#FFFFFF", "Please wait...", "&nbsp;Testing your browser. Please wait..."

if bhObj.Browser <> "IE" OR bhObj.Plugin_Flash = 0 OR bhObj.JavaScript = False then

Response.Redirect "/nodice.asp" 

end if

<html>Congrats, you have IE with the Flash plugin and JavaScript enabled!</html>

 

Code sample for ASP.NET (in C#) with .NET version of BrowserHawk:

 

<%@ Page language="c#" %>

<%@ Import Namespace="cyScape.BrowserHawk" %>

 

<%

BrowserObj bhObj = BrowserObj.GetBrowser();

ExtendedOptions options = new ExtendedOptions();

options.AddProperties("JavaScriptEnabled, Plugin_Flash");

options.PageMessage = "&nbsp;Testing your browser. Please wait...";

options.PageTitle = "Please wait...";

options.BodyTag = "BGCOLOR=#FFFFFF";

ExtendedBrowserObj extBrow = BrowserObj.GetExtendedBrowser(options);

// Note how we are checking the extended properties using the ExtendedBrowserObj class

// and not the BrowserObj class as in the ActiveX version.

if (bhObj.Browser != "IE" || extBrow.Plugin_Flash == 0 || extBrow.JavaScriptEnabled == false)

Response.Redirect("/nodice.aspx"); 

%>

<html>Congrats, you have IE with the Flash plugin and JavaScript enabled!</html>

 

Note that you can save a line of code by passing in the extended properties to check when calling the ExtendedOptions constructor. This results in this class calling AddProperties for you. This is a cleaner and bit easier way to code with the component, but we explicitly use the AddProperties method here and throughout the documentation for clarity. For instance, in the above example instead of:

ExtendedOptions options = new ExtendedOptions();

options.AddProperties("JavaScriptEnabled, Plugin_Flash");

You can just use:

ExtendedOptions options = new ExtendedOptions("JavaScriptEnabled, Plugin_Flash");

Summary

 

If you have been programming with the ActiveX version of BrowserHawk for some time, the new object model found in the .NET version at first may seem like quite a change. This change was made for the better in order to provide a cleaner, more efficient, and more flexible object model for your .NET programming needs. After a few minutes of practice you should be up to speed with this new model and can proceed to migrate your existing ASP code that uses the ActiveX version over to ASP.NET using the native .NET version.

 

See Also:

About the Migrating From ActiveX to .NET Guide