2

With reference to This question for how to load links with blank target in WebView, I tried the given solution :

 func webView(_ webView: WKWebView!, createWebViewWith configuration: WKWebViewConfiguration!, for navigationAction: WKNavigationAction!, windowFeatures: WKWindowFeatures!) -> WKWebView! {

        if navigationAction.targetFrame == nil {
                //This request is blank here
                webView.load(navigationAction.request)  
        }
        return nil
    }

Still as mentioned by Jason Murray in comments, When I click on a link(button) from inside WKWebView, the WKUIDelegate method above, does gets called but has navigationAction.request = "" (the request url is always blank) and hence nothing happens when webView.load("") gets called, so the webview directs to a blank white page.

Then I tried Solution for above issue as mentioned here, But I guess(as I don't have much knowledge in JS) this solution injects JS based on mentioned specific tag.

My web page have buttons with href tag as below :

<a _ngcontent-ylq-c12="" class="buttonGreen" href="javascript:void(0);" id="Buy_QP_WibeWide" btnuniqueid="WibeWide_1" title="Haz click para contratar en la web de la aseguradora"></a>
  • How to make it work and get the correct request/url to load the correct page ?
  • Does it need a workaround with the injected JS as mentioned in second link's solution ?

PS : Contrary to the update in solution given by @https://stackoverflow.com/users/2986164/shrutim, I am running Swift 4.2 and still facing the issue.

Tarun Tanwar
  • 41
  • 12
  • how do you expect this link to behave? link without address to open - wont do anything. link with href="javascript:void(0);" its kind of opening nothing or acts as refresh. I believe old IE has this behaviour but it is by the specs... so all is good here :) – Deian Oct 20 '20 at 03:37
  • @Deian this is not the case here: there is an url but it is not provided in the URLRequest in this target=_blank case – Jérôme Beau Jul 26 '21 at 13:18

0 Answers0