I using WebViewExtras ver. 2.20
I am trying to call B4A sub from my web site
This below is my code but cant start b4a sub from html page loaded into WebView
B4X:
Sub Globals
Dim WebView1 As WebView
Dim WebViewExtras1 As WebViewExtras
Dim html As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("111")
' WebView1.Initialize("")
WebViewExtras1.Initialize(WebView1)
' WebViewExtras1 now has all the methods and properties of WebView1 plus it's additonal methods and properties
' so you can use WebView1 to get/set WebView properties/methods
' or use WebViewExtras1 to get/set WebView1 properties/methods with the additional properties/method of WebViewExtras
Dim WebViewClient1 As DefaultWebViewClient
WebViewClient1.Initialize("WebViewClient1")
WebViewExtras1.JavaScriptEnabled=True
WebViewExtras1.SetWebViewClient(WebViewClient1)
WebViewExtras1.AddJavascriptInterface(WebViewClient1,"B4A")
WebViewExtras1.CanGoback()
WebViewExtras1.LoadUrl("https://192.168.0.106/MobileOffice/D2548BA4-E6FD-43A0-9423-F4AE0BC7B710/Phone/Auth/Authorize/" & pId.GetDeviceId)
End Sub
Sub WebViewGoBack_Request()
WebViewExtras1.GoBackOrForward(-1)
Log(9)
End Sub
Well, I would narrow the issue down by replacing the B4a.CallSubPlus with a known working "alert" call:
B4X:
<script>
function goBack() {
alert("This is a test");
}
</script>
This will narrow down if the problem is that the goBack is not being called, or if the B4A.CallSub is not working right, so then we will know were to focus our troubleshooting efforts.
So, does the Alert pop-up display when you click the hyperlink using the above modification?
Maybe not the same thing, but I’ve just work with webview one time long ago.
Maybe you can try this example and see if it works for you, and what you need is similar
Hi everyone: After several test, now I can use the jSignature javascript plugin I was using in my web, in my B4A app, in order to update my database from b4a the same way I'm doing in my web. I know there are some solutions to do this in B4A, but I need to do it this way because I was using it...
Before uploading your ZIP file, please modify your sample project to load a local HTML page into webview (since we will not have access to your private 192.xxx server)
Dim JavascriptInterface1 As DefaultJavascriptInterface
JavascriptInterface1.Initialize
Now full working code is:
B4X:
Sub Globals
Dim WebView1 As WebView
Dim WebViewExtras1 As WebViewExtras
Dim html As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("111")
' WebView1.Initialize("")
WebViewExtras1.Initialize(WebView1)
' WebViewExtras1 now has all the methods and properties of WebView1 plus it's additonal methods and properties
' so you can use WebView1 to get/set WebView properties/methods
' or use WebViewExtras1 to get/set WebView1 properties/methods with the additional properties/method of WebViewExtras
Dim WebViewClient1 As DefaultWebViewClient
WebViewClient1.Initialize("WebViewClient1")
WebViewExtras1.JavaScriptEnabled=True
WebViewExtras1.SetWebViewClient(WebViewClient1)
'This row is useless
'WebViewExtras1.AddJavascriptInterface(WebViewClient1,"B4A")
Dim JavascriptInterface1 As DefaultJavascriptInterface
JavascriptInterface1.Initialize
WebViewExtras1.AddJavascriptInterface(JavascriptInterface1,"B4A")
WebViewExtras1.CanGoback()
WebViewExtras1.LoadUrl("https://192.168.0.106/MobileOffice/D2548BA4-E6FD-43A0-9423-F4AE0BC7B710/Phone/Auth/Authorize/" & pId.GetDeviceId)
End Sub
Sub WebViewGoBack_Request()
WebViewExtras1.GoBackOrForward(-1)
Log(9)
End Sub