You can define PowerBuilder user events for WebBrowser and then trigger the event in JavaScript.
The PowerBuilder user event to be registered should be defined as follows.
event type string eventName(string as_arg);
User events can be defined with one string-type parameter and string-type return value (code example) or no parameters.
User events must be registered by RegisterEvent function before they can be triggered in JavaScript.
After a PowerBuilder user event is registered successfully, it can be triggered by JavaScript on Web in the following ways (assuming the name of the registered event is TestPBEvent)
-
Syntax 1: trigger the user event synchronously and return a string
webBrowser.TestPBEvent ('The event is synchronously triggered by JavaScript')
-
Syntax 2: trigger the user event asynchronously and return a JavaScript Promise object.
webBrowser.asyncfun.prototype.TestPBEvent ('The event is asynchronously triggered by JavaScript')
Note
In the registered PowerBuilder user event, only the asynchronous function EvaluateJavascriptAsync can be called; it is not allowed to call any other synchronous functions (such as EvaluateJavascriptSync), otherwise, the application will get stuck. This issue may occur in other WebBrowser events such as TitleTextChanged. To work around this issue, you can move scripts to a function out of WebBrowser control and post call this function in the event.