SetJSEval Method (.NET)

 

Syntax:

 extOptions.SetJSEval(string name, string code);

name: the name of the property you will use later to retrieve the result of the code which is executed.

code: The custom JavaScript code to be executed in the visitor's browser.

 

The SetJSEval method enables BrowserHawk to execute your own custom JavaScript code on the visitor's browser. The result of this code execution can then be retrieved using the ExtendedBrowserObj GetJSEval method.

 

By using the SetJSEval method you are able to interface with any external browser tests you wish to write, or with any other arbitrary data you wish.

 

For example, assume you have a JavaScript code snippet you wish to execute to perform your own custom browser sniffing function not natively provided by BrowserHawk.  This method enables you to have your code executed at the same time BrowserHawk executes its other tests, and to obtain the results just as if BrowserHawk natively supported that function.

 

Tip: If your custom JavaScript code requires a supporting function(s) or objects (such as an ActiveX control or plug-in), you can write out those supporting functions or objects using the PageMessage property.

 

Note: This method requires the Enterprise Edition of BrowserHawk.

 

C# Example:

<%

ExtendedOptions options = new ExtendedOptions();

options.SetJSEval("localtime", "new Date().toString()");

ExtendedBrowserObj extBrow = BrowserObj.GetExtendedBrowser(options);

string browserTime = (string) extBrow.GetJSEval("localtime");

%>

<html>

Your local time is: <% = browserTime %>

</html>

 

Tip: See the ret-eval.aspx sample distributed with BrowserHawk for an alternate example of how to execute custom JavaScript to obtain custom results which are then enforced by BrowserHawk's Rules Enforcement Technology (RET).

 

See Also:

GetJSEval Method (.NET)

GetJSEvalNames Method (.NET)

Plugin_Custom Property (.NET)