WKWebView gives BLANK navigationAction.request for SOME links with target=blank

做~自己de王妃 提交于 2020-07-22 22:13:45

问题


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.

来源:https://stackoverflow.com/questions/59862536/wkwebview-gives-blank-navigationaction-request-for-some-links-with-target-blank

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!