With a UIWebView to intercept the ShouldStartLoad event all I have to do is this:
_webView.ShouldStartLoad += (webView, request, navigationType) => { return true }
How do I handle this with the WKWebView?
You will need to override DecidePolicy in your WKNavigationDelegate subclass.
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);
}
}
...
}
Then set the webview's navigation delegate to your new class.
_webView.NavigationDelegate = new WebNavigationDelegate(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With