Previous topicNext topic
Help > Events >
JSMessage

JSMessage Event

Fired when a JavaScript code invokes the vbH().RaiseMessageEvent function.

Syntax

Private Sub   object _JSMessage(sMsg As String, sMsgContent As String, oJSONContent As String)

The JSMessage event syntax has these parts:

Element Description
Object The object placeholder represents an OrdoWebView2 control
sMsg String. the title identifying the message
sMsgContent String. the message
oJSONContent a Json String. a Json file containing the function's response if needed

Remarks    

  • Here is an example of using this event in Visual Basic 6
    Create a new project with a Form, an OrdoWebView control, a Timer control, then copy the following code into the code window of the form :

    Option Explicit

    Private Sub Form_Load()
        OrdoWebView1.Init
    End Sub

    Private Sub OrdoWebView1_InitComplete()
        OrdoWebView1.AddScriptToExecuteOnDocumentCreated "function getQSValue(qsExpr){return document.getElementById((qsExpr)).value}"
        OrdoWebView1.AddScriptToExecuteOnDocumentCreated "function btn1_click(){ vbH().RaiseMessageEvent('btn1_click','') }"
        'avoid navigating in the InitComplete event. Trigger the first navigation with a Timer, instead

        
    Timer1.Interval = 100
    End Sub

    Private Sub OrdoWebView1_JSMessage(ByVal sMsg As String, ByVal sMsgContent As String, oJSONContent As String)
        Select Case sMsg
           Case "btn1_click"
            MsgBox "txt1.value: " & OrdoWebView1.RunJs("getQSValue", "txt1")
        End Select
    End Sub

    Private Sub Timer1_Timer()
        Timer1.Interval = 0
        OrdoWebView1.NavigateToString "<!DOCTYPE html><html><head><title>AppTitle</title></head><body>" & _
                              "<div>Hello World...</div>" & _
                              "<input id='txt1' value='OrdoConcept'>" & _
                              "<button id='btn1' onclick='btn1_click()' >Button1</button>" & _
                              "</body></html>"
    End Sub