Few months ago I made a simple Browser that surf on a specified webpage and avoid any kind of unwanted page to get opened through the simple event Override Url of the WebView control
Unfortunately this time I'm working with a website that is getting fully loaded only using the library UltimateWebView2 , thus, through the examples in that topic, I came with the following code
I did my best removing the things I didnt need from the "Example 1", and tried to understand its logic, but eventhough the CreateWindow event fires, it doesn't really care if the url contains "whipwhip" but opens links which doesn't contain it.
B4X:
Private Sub WebView1_OverrideUrl (Url As String) As Boolean
If Url.StartsWith("https://streamingcommunity.buzz/")= True Then
Return False
Else
Return True
End If
End Sub
Unfortunately this time I'm working with a website that is getting fully loaded only using the library UltimateWebView2 , thus, through the examples in that topic, I came with the following code
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private txtUrl As EditText
Public UltimateWebView1 As UltimateWebView
Private WebChromeClient As UltimateWebChromeClient
Private fp As FileProvider
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim URL As String = $"
https://anonpaste.pw/v/749fd052-5192-4d20-83b6-17eb9b77e0ea#Ir-jVwPIgcDQsbsdBNoQqH7JBqtdjQHZESNC1v4lupE
"$
txtUrl.Text = URL
fp.Initialize
WebChromeClient.Initialize2("UltimateWebView1",UltimateWebView1).AllowFullScreenVideo(True,False) 'AllowFullScreenVideo only if you need, it is not necessary to set.
UltimateWebView1.Settings.AllowContentAccess=True
UltimateWebView1.Settings.AllowFileAccess=True
UltimateWebView1.Settings.AllowFileAccessFromFileURLs=True
UltimateWebView1.Settings.AllowUniversalAccessFromFileURLs=True
UltimateWebView1.Settings.BuiltInZoomControls=False
UltimateWebView1.Settings.JavaScriptEnabled=True
UltimateWebView1.Settings.DomStorageEnabled=True
UltimateWebView1.Settings.JavaScriptCanOpenWindowsAutomatically=True
UltimateWebView1.Settings.MediaPlaybackRequiresUserGesture=False
UltimateWebView1.Settings.SaveFormData=True
UltimateWebView1.Settings.GeolocationEnabled=True
UltimateWebView1.Settings.SupportMultipleWindows=True
UltimateWebView1.CookieManager.AcceptCookies=True
UltimateWebView1.CookieManager.AcceptFileSchemeCookies=True
UltimateWebView1.CookieManager.AcceptThirdPartyCookies=True
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub btnGo_Click
UltimateWebView1.LoadUrl(txtUrl.Text)
End Sub
Private Sub UltimateWebView1_OverrideUrl (Request As WebResourceRequest) As Boolean 'Works from API level 1 and above.
Dim url As String =Request.Url
' Controlla se l'URL contiene "whipwhip"
If url.Contains("whipwhip")=True Then
' Apri la nuova finestra
Log("over ride url : " & url)
'UltimateWebView1.LoadUrl(url)
Return False
Else
Return True
End If
End Sub
Private Sub UltimateWebView1_CreateWindow (OverridenRequest As WebResourceRequest, ChildWebView As WebView, IsDialog As Boolean, IsUserGesture As Boolean) As Boolean
' Ottieni l'URL richiesto
Dim url As String = OverridenRequest.Url
' Controlla se l'URL contiene "whipwhip"
If url.Contains("whipwhip")=True Then
' Apri la nuova finestra
Log("Creating new window for URL: " & url)
UltimateWebView1.LoadUrl(url)
Return True
Else
Return False
End If
End Sub
I did my best removing the things I didnt need from the "Example 1", and tried to understand its logic, but eventhough the CreateWindow event fires, it doesn't really care if the url contains "whipwhip" but opens links which doesn't contain it.
Last edited: