|
(EzToolsLib)
Using the DOM's "window.external" mechanism of the
webbrowser to communicate with your application via the
WOW control is one of its most powerful features.
Using this feature, you can raise generic events to your
application code. You access the external object via the "external" property
of the webpage's window object. For example, for an Anchor tag you
would do this:
<a href="#" onClick="window.external.raiseEvent(this, 'WOW Test clicked',
'another parameter');">WOW Test</a>
You can do the same for any HTML element which supports
the onClick event. Of course, you don't have to use the element's onClick event
- you can use any event, such as onBlur. Its entirely up to you when and
how you want to fire events into the application.
By default, window.external is set to the WOW control
itself, which forwards RaiseEvent method calls to the host application in the
form of the OnRaiseEvent event. Here is how you would trap the above event
raised when the user clicks on the hyperlink:
WowCtl1_OnRaiseEvent( htmlObj As
Object, vtParam1 As Variant, vtParam2 As Variant )
This is well and good for most applications. But
you may need more than just two parameters. In this case, you can set your own custom "external" COM object so that you can call any method on your
object's interface directly from the webpage using Javascript via the DOM's "window.external" member. The
default custom interface that WOW provides has only two methods: RaiseEvent and
RaiseEvent2. You can set your own custom COM object (such as a VB Class or
Form object) using the WowCtl.SetExternal method. If using .NET, you can
even set a .NET class object!
For example, suppose the
main form in your VB app has a function named DoSomething that takes a single
string parameter. Here is how you could call it from a webpage. In
the VB code for your Form object, add this line:
wow1.SetExternal
me
Now in your webpage code you can call functions on the
Form directly, like this:
<a href="#" onclick="window.external.CallMyMethod('a
parameter')">Call my Custom Method</a>
There is also the Custom property, which
allows you to still use window.external.raiseEvent, but to
also set your own external object, like this:
wow1.Custom
= me
This allows you to still use the default external
object and set your own custom object accessible through
the external.Custom property. So you still have
available the external.RaiseEvent methods, but you can
access your object too.
Example:
<a href="#" onclick="window.external.Custom.CallMyMethod('a
parameter')">Call my Custom Method</a>
|