问题
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