How Do I Interact with a Web Page Running in a Browser Control? (Magic xpa 3.x)
When you are displaying a web page in a Browser control, you can have that web page send you information, and you can send information to the web page.
A web page can send information to your Rich Client program by using a special event, called MGExternalEvent. This is coded into the code of the web page. For instance, here is a VBScript that sends a date argument back to Magic xpa:
// This VBScript segment handles the click event of the Calendar object.
// Upon a click on the object the MGExternalEvent function is called with
// the expected arguments.
// This allows external modules on the page to interact with the Magic xpa
Sub Calendar1 click()
document.Calendar1.Day & ‘|’
document.Calendar1.Month & ‘|’
This will raise MGExternalEvent, sending the three date values in one string delimited by ‘|’. This is important because only one parameter, a BLOB, can be returned.
Now, in the Rich Client program, you need to handle that event. This is done by creating a handler for the Internal event called External Event.
All that remains is to parse the BLOB according to what was sent. In this example, the BLOB is text, so it is defined as Ansi, allowing the use of the DVal function directly on the BLOB. The various string parsing functions in Magic xpa -- such as StrToken() and the conversion functions -- are quite useful for this kind of parsing.
You can also send data and commands to the browser interactively.
You can also change the entire content of the page by using the BrowserSetContent() function. This replaces all the HTML that the Browser control is displaying. Similarly, BrowserGetContent() will return the entire contents of the page.
Note: You can alternatively use the .NET browser control, System.Windows.Forms.WebBrowser, which, like all .NET controls, gives you more low-level control but has a higher learning curve.
The Rich Client Samples project (program RRC07 )