Dynamic property access

 

BrowserHawk allows you to access browser properties dynamically at run time. This is accomplished using enumeration.

Enumeration with the ActiveX Component

 

With the BrowserHawk ActiveX object properties are accessed dynamically using the object's Item method, which is the default method. Using the Item method allows you to specify the property value you wish to retrieve by using the property name contained in program variable. For example:

 

<%

set browObj = Server.CreateObject("cyScape.browserObj")

propToGet = "Majorver"

majVerNum = browObj.Item(propToGet)

set browObj = Nothing

%>

 

Likewise you can use a similar technique to enumerate all properties defined for a browser at run-time and retrieve their associated values. The following example demonstrates this:

 

<%

set browObj = Server.CreateObject("cyScape.browserObj")

For each property in browObj

propVal = browObj.Item(property)

response.write (property & "-" & CStr(propVal) & "<BR>")

Next

set browObj = Nothing

%>

 

Tip: Since Item is the default method, you can shorten your code by leaving this method name out. For example, the following two lines of code execute identically:

 PropVal = browObj(property)

 PropVal = browObj.Item(property)

 

See the showbrow.asp sample for a full working example of accessing properties dynamically.

Enumeration with the .NET Component

 

With the native .NET version of BrowserHawk object properties are accessed dynamically using the [string] notation on the class being accessed dynamically. For example (in C#):

 

BrowserObj thisBrowser = BrowserObj.GetBrowser();

string propToGet = "Browser";

string propertyValue = thisBrowser[propToGet];

 

To enumerate all properties in the BrowserObj class, for example, you would do this:

BrowserObj thisBrowser = BrowserObj.GetBrowser();

foreach (string propertyName in thisBrowser) {

Response.Write("Property: " + propertyName + ", Value: " + thisBrowser[propertyName].ToString() + "<br>"; 

}

 

See the showbrow.aspx sample for a full working example of accessing properties dynamically.

 

See Also:

Working with properties

Using BrowserHawk in your scripts

Tips and Techniques