RegisterEvent

Description

Registers the PowerBuilder user defined event so they can be triggered in JavaScript.

Applies to

WebBrowser controls

Syntax

controlname.RegisterEvent (string eventname) 

Argument

Description

controlname

The name of the WebBrowser control.

eventname

The name of the user-defined event to be registered.


Return value

Integer.

Returns values as follows.

1 -- the event is registered successfully.

-1 -- the event is already registered.

-2 -- failed to get the browser instance.

Examples

The following example defines a PowerBuilder user event which is then triggered in JavaScript in wb_1, and the result of the JavaScript which is returned in a JSON string is parsed by the JSONParser object.

Note that this user event should not call any other WebBrowser function, otherwise the application may get stuck.

//define a user event: ue_getstring in wb_1
event type string ue_getstring(string as_arg);
string ls_String
ls_String = "This is PB Event!" + "~r~nFrom JavaScript:" + as_arg
Return ls_String
end event

Integer li_Return
String ls_JS, ls_Result, ls_Error
JsonParser lnv_JsonParser
Long ll_RootObject
String ls_Type, ls_Value

li_Return = wb_1.RegisterEvent("ue_getstring")
If li_Return = 1 Then
        ls_JS = "function event1() { return window.webBrowser.ue_getstring('Hi,PB!');} event1();"
        li_Return = wb_1.EvaluateJavascriptSync(ls_JS, ls_Result, ls_Error)
        If li_Return = 1 Then
               lnv_JsonParser = Create JsonParser
               lnv_JsonParser.LoadString(ls_Result)
               ll_RootObject = lnv_JsonParser.GetRootItem()
               ls_Value = lnv_JsonParser.GetItemString( ll_RootObject, "value" )
        End If
End If
//{"type":"string","value":"This is PB Event!\r\nFrom JavaScript:Hi,PB!"}
MessageBox( "Tips", ls_Result )

//This is PB Event!
//From JavaScript:Hi,PB!
MessageBox( "Tips", ls_Value )

See also

CancelDownload

EvaluateJavascriptAsync

EvaluateJavascriptSync

GetSource

GoBack

GoForward

Navigate

PrintAsPDF

PauseDownload

ResumeDownload

Refresh

StopNavigation

UnregisterEvent

Zoom