Android Question WebkitWebView click hyper link target=blank, ChildWindow does not load URL

kofiking

Member
I am trying to use the WebkitLibrariesSet library to create a multi-window browser. The problem I encountered is that after the WebkitWebView click hyper link with target="_blank", WebkitWebView successfully creates a new ChildWindow, but the ChildWindow does not load any URLs and is blank. How to get the URL of the ChildWindow or how to let the ChildWindow load the URL? Can anyone help me? Thank u!


all my code:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    
    Private WebkitWebView1 As WebkitWebView
    Dim NewUltimateView As WebkitWebView
    
    
    
    Private ASViewPager1 As ASViewPager
    
    Private Label1 As Label
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    WebkitWebView1.Initialize(Me,"WebkitWebView1")

    WebkitWebView1.JavaScriptEnabled=True
    WebkitWebView1.Settings.AlgorithmicDarkeningAllowed=True
    WebkitWebView1.Settings.AllowContentAccess=True
    WebkitWebView1.Settings.AllowFileAccess=True
    WebkitWebView1.Settings.AllowFileAccessFromFileURLs=True
    WebkitWebView1.Settings.SupportMultipleWindows=True
    WebkitWebView1.Settings.JavaScriptCanOpenWindowsAutomatically=True
    WebkitWebView1.Settings.DomStorageEnabled=True
    WebkitWebView1.Settings.DatabaseEnabled=True
    WebkitWebView1.Settings.LoadWithOverviewMode=True
    WebkitWebView1.Settings.UseWideViewPort=True
    WebkitWebView1.Settings.LoadsImagesAutomatically=True
    
    WebkitWebView1.WebView.LoadHtml ($"
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    </head>
    <body>
        Click any link and wait some seconds
        <br><br>
        <a href="https://www.apple.com" target="_blank">Link with target="_blank"</a>
        <br><br>
        <a href="https://www.bing.com">Link without target="_blank"</a>
    </body>
    "$)
    
    ASViewPager1.AddPage(WebkitWebView1.View,"")
    
    
End Sub

Sub Activity_Resume
    
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Private Sub WebkitWebView1_CreateChildWindow (IsDialog As Boolean, IsUserGesture As Boolean) As WebView 'Works from API level 1 and above. SupportMultipleWindows option must be enabled.
    Log("Added New Child Window")
    ToastMessageShow("Added New Child Window",False)
    'Return Null if you do not want to create child window. Page will not be loaded!
    
    NewUltimateView.Initialize(Me,"NewUltimateView")
    NewUltimateView.EnableSlowWholeDocumentDraw
    NewUltimateView.Settings.ImportSettingsFrom(WebkitWebView1.WebView) 'Import settings from main UltimateWebView without referencing.
    
    NewUltimateView.CookieManager.AcceptCookies=True
    NewUltimateView.CookieManager.AcceptFileSchemeCookies=True
    NewUltimateView.CookieManager.AcceptThirdPartyCookies=True
    NewUltimateView.CookieManager.Flush
    Log(NewUltimateView.OriginalUrl)
    
    NewUltimateView.Width=100%x
    NewUltimateView.Height=100%y
    
    ASViewPager1.AddPage(NewUltimateView.View,"")
    
    
    Return NewUltimateView.WebView
End Sub


Private Sub NewUltimateView_OverrideUrl (Url As String) As Boolean 'Works from API level 1 to API level 23.
    Log("NewUltimateView_OverrideUrl")
    
End Sub



Private Sub NewUltimateView_OverrideUrl2 (WebResourceRequest As WebkitWebResourceRequest) As Boolean 'Works from API level 24 and above. WebkitWebResourceRequest library required.
    Log("NewUltimateView_OverrideUrl2")
    
End Sub





Private Sub WebkitWebView1_OverrideUrl (Url As String) As Boolean 'Works from API level 1 to API level 23.
    Log("WebkitWebView1_OverrideUrl")
    
    
End Sub

Private Sub WebkitWebView1_OverrideUrl2 (WebResourceRequest As WebkitWebResourceRequest) As Boolean 'Works from API level 24 and above. WebkitWebResourceRequest library required.
    Log("WebkitWebView1_OverrideUrl2")
    
End Sub


Private Sub WebkitWebView1_PageFinished (Url As String) 'Works from API level 1 and above.
    Log("PageFinished")
    
End Sub



Sub Activity_KeyPress (KeyCode As Int) As Boolean

    If KeyCode = KeyCodes.KEYCODE_BACK  Then    'back key pressed
        WebkitWebView1.GoBack
        Return True   'Return True to consume the event
    End If
'    Return False
End Sub


Private Sub Button1_Click
    ToastMessageShow(WebkitWebView1.WebChromeClient.WebViewsChildrenViews,False)
    Label1.Text=WebkitWebView1.WebChromeClient.WebViewsChildrenViews.Size
End Sub
 

Attachments

  • Mybrowser.zip
    159.5 KB · Views: 125

Ivica Golubovic

Active Member
Licensed User
You made a mistake at the start. A child view, as the name suggests, is a child of the main view (main WebkitWebView). This means that this view is directly controlled by the main view and is not independent (you can't change it's parent). In the line shown below, you have reset the state of the new view (child view) to a new instance, which by default sets the Url to blank.

Line:
ASViewPager1.AddPage(NewUltimateView.View,"")

In your case (where you are using a custom html page) you have to use WebkitJavascriptInterface and create a new independent WebkitWebView when a link or button is clicked. You should also send the web address via the javascript interface, which should be loaded in the new WebkitWebView object.
 
Upvote 0

kofiking

Member
OK, thank you for your guidance, I will try again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…