iOS Question webview click hyper link target=blank without any action

youjunjer

Member
Licensed User
Longtime User
Did anyone have the same problem? In my webview, I click a hyperlink with a target='_blank' will nothing happen.
I also tried WKwebview. nor of them worked. I try use 'PageFinished' and 'OverrideUrl' to catch the event. But it did not work too.
I google this problem. find some link
any idea?
 

Semen Matusovskiy

Well-Known Member
Licensed User
Set a delegate (after initializing WebView)

B4X:
    Dim no As NativeObject = WebView1
    no.SetField ("UIDelegate", Me)

Describe a subroutine, which will receive URL, when target="blank". For example:
B4X:
Private Sub TargetBlank (URL As Object)
    WebView1.LoadUrl (URL)      
End Sub

Add a delegate:
B4X:
#If OBJC
#import <WebKit/WebKit.h>
- (WKWebView *) webView:                        (WKWebView *)              webView
                createWebViewWithConfiguration: (WKWebViewConfiguration *) configuration
                forNavigationAction:            (WKNavigationAction *)     navigationAction
                windowFeatures:                 (WKWindowFeatures *)       windowFeatures
        {       
        [[b4i_main new].bi raiseEvent: nil event: @"targetblank:" params: @[navigationAction.request.URL]];       
        return nil;
        }   
#End If

If a module name is not 'Main', change a line with raiseEvent.
 

Attachments

  • Blank.zip
    2.7 KB · Views: 258
Last edited:
Upvote 0
Top