B4J Question WebView1_OverrideUrl in B4J !?

ghadiri

New Member
Hello,
I used a webview in B4A and I open the internal links loaded in the webview in the system’s default browser using the WebView1_OverrideUrl event. However, the WebView1_OverrideUrl event does not exist in B4J. How can I open links in the system’s default browser in B4J since this event is not available?

B4X:
Sub WebView1_OverrideUrl(Url As String) As Boolean
    Dim i As Intent
    i.Initialize(i.ACTION_VIEW, Url)
    StartActivity(i)
    Return True
End Sub
 

ghadiri

New Member
This answer is not correct for my question! I want in B4J when a link is clicked inside a WebView, that link should not open inside the WebView but rather in the default system browser like Chrome or Firefox.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Open the page using jShell and reload the WebView with original html.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private WebView1 As WebView
    Private html As String
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    html = $"<a href="https://www.w3schools.com">Open page in default browser</a>"$
    WebView1.LoadHtml(html)
End Sub

Private Sub WebView1_LocationChanged (Location As String)
    If Location.Contains("w3schools") Then
        Sleep(0)
        WebView1.LoadHtml(html)
        OpenBrowser(Location)
    End If
End Sub

Private Sub OpenBrowser (url As String)
    Dim shl As Shell
    shl.Initialize("shl", "cmd", Array As String("/c", "start", url))
    shl.Run(3000)
End Sub
 
Upvote 0
Top