You can create a B4A event sub and have the javascript call it and pass the result:
B4X:
Javascript="B4A.CallSub('GetTitle_Event', false, document.title)"
wve.executeJavascript(wv, Javascript)
Sub GetTitle_Event(Title As String)
Log("Title=" & Title)
End Sub
@JohnC
It does not work in ultimatewebview2.
' zwa is an instance of ultimatewebview2
i tried
B4X:
Private Sub zwv_PageFinished (Url As String) 'Works from API level 1 and above.
Dim Javascript As String ="document.title"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub Evaluatejavascriptresult_event(res As String)
Log("title " & res)
End Sub
You removed critical code from my example like the "B4A.CallSub" part.
So, just try these lines exactly as shown and do NOT change anything to make sure you don't introduce a new problem:
B4X:
Private Sub zwv_PageFinished (Url As String)
Dim Javascript as string = "B4A.CallSub('GetTitle_Event', false, document.title)"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub GetTitle_Event(Title As String)
Log("Title=" & Title)
End Sub
You removed critical code from my example like the "B4A.CallSub" part.
So, just try these lines exactly as shown and do NOT change anything to make sure you don't introduce a new problem:
B4X:
Private Sub zwv_PageFinished (Url As String)
Dim Javascript as string = "B4A.CallSub('GetTitle_Event', false, document.title)"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub GetTitle_Event(Title As String)
Log("Title=" & Title)
End Sub
Hi, On my website I use javascript to call a b4x sub : (webview) B4X.CallSub("Log_TextToB4a", true, result['id_place']); How I do this with Ultimate Webview2 ? Thanks rgs J.
Sub Globals
Private jsi As UltimateJavascriptInterface
End Sub
Sub Activity_Create
jsi.Initialize
zwv.addJavascriptInterface(jsi, "B4X")
End Sub
Private Sub zwv_PageFinished (Url As String)
Dim Javascript as string = "B4A.CallSub('GetTitle_Event', false, document.title)"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub GetTitle_Event(Title As String)
Log("Title=" & Title)
End Sub
Sub Globals
Private jsi As UltimateJavascriptInterface
End Sub
Sub Activity_Create
jsi.Initialize
zwv.addJavascriptInterface(jsi, "B4X")
End Sub
Private Sub zwv_PageFinished (Url As String)
Dim Javascript as string = "B4A.CallSub('GetTitle_Event', false, document.title)"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub GetTitle_Event(Title As String)
Log("Title=" & Title)
End Sub
Private Sub zwv_PageFinished (Url As String) 'Works from API level 1 and above.
txtUrlZomato.Text=Url
Dim Javascript As String ="document.title"
zwv.EvaluateJavascript(Javascript)
End Sub
Sub zwv_evaluatejavascriptresult(res As String)
Log("title " & res)
End Sub