实现WKWebview代理方法 代码如下:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
// let requestUrlStr = navigationAction.request.url?.absoluteString
//需要判断targetFrame是否为nil,如果为空则重新请求
if navigationAction.targetFrame == nil {
webView.load(navigationAction.request)
}
decisionHandler(.allow)
}