使用UIWebView拦截ShouldStartLoad事件,我所要做的就是:
_webView.ShouldStartLoad + =(webView,request,navigationType)=> {return true}
如何使用WKWebView处理此问题?
答案 0 :(得分:4)
您需要覆盖WKNavigationDelegate子类中的 DecidePolicy 。
public class WebNavigationDelegate : WKNavigationDelegate
{
...
public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
var url = navigationAction.Request.Url;
if (true) //Whatever your test happens to be
{
decisionHandler(WKNavigationActionPolicy.Allow);
}
else
{
decisionHandler(WKNavigationActionPolicy.Cancel);
}
}
...
}
然后将webview的导航委托设置为新课程。
_webView.NavigationDelegate = new WebNavigationDelegate(this);