Hi,
we decide to use more functionality from webview, because the main components are already working in html. So, i try to interact between webview and b4x.
I try the example which pulls a webview function from the activity. that works. But more important is the other way, pushing from the webview to the activity.
I found a article here that says the easiest way for b4a and b4i is the "OverrideUrl" from webview. I´ve tried it - it does nothing :/
Can anyone tell me what my mistake is?
In the html is a button
Webview1_OverrideUrl will not called...
Regards
Matze
we decide to use more functionality from webview, because the main components are already working in html. So, i try to interact between webview and b4x.
I try the example which pulls a webview function from the activity. that works. But more important is the other way, pushing from the webview to the activity.
I found a article here that says the easiest way for b4a and b4i is the "OverrideUrl" from webview. I´ve tried it - it does nothing :/
Can anyone tell me what my mistake is?
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Private WebView1 As WebView
Dim we As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
we.addJavascriptInterface(WebView1,"B4A")
WebView1.LoadUrl(WebViewAssetFile("index.html"))
End Sub
Sub TheContentIs(content As String)
Msgbox(content,"Content From JS")
End Sub
Sub WebViewAssetFile (FileName As String) As String
#if B4J
Return File.GetUri(File.DirAssets, FileName)
#Else If B4A
Dim jo As JavaObject
jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
If jo.GetField("virtualAssetsFolder") = Null Then
Return "file:///android_asset/" & FileName.ToLowerCase
Else
Return "file://" & File.Combine(jo.GetField("virtualAssetsFolder"), _
jo.RunMethod("getUnpackedVirtualAssetFile", Array As Object(FileName)))
End If
#Else If B4i
Return $"file://${File.Combine(File.DirAssets, FileName)}"$
#End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
we.executeJavascript(WebView1,"javascript: doCallBack();")
End Sub
Sub Webview1_OverrideUrl (Url As String)
Msgbox(Url,"Called")
If Url.Contains ("#") Then
Msgbox(Url,"Contains Hash")
End If
End Sub
In the html is a button
HTML:
<button onclick="changeHash('#nice',this)">Push me</button>
</body>
<script>
function changeHash(h,t){
window.location.href=h
t.innerHTML=h;
}
</script>
Webview1_OverrideUrl will not called...
Regards
Matze