simpleProgrammer
simpleProgrammer

Reputation: 189

UWP Webview NavigationStarting event handler is not working when URL is not Valid

Subscribe EvenHandler:

wv.NavigationStarting += webView_NavigationStarting;

EvenHandler Implementation

private static void webView_NavigationStarting(object sender, WebViewNavigationStartingEventArgs args)
{
    var url = args.Uri.AbsoluteUri.Substring(args.Uri.AbsoluteUri.LastIndexOf("/") + 1);
    int parameterCount = url.Split('_').Length;
}

When URL is valid it navigates perfectly fine, otherwise EvenHandler was not called.

And the pop up below shows:

enter image description here

Upvotes: 1

Views: 809

Answers (1)

Pedro Lamas
Pedro Lamas

Reputation: 7233

You can use the WebView.UnsupportedUriSchemeIdentified event to handle unknown uri's.

private void webView_OnUnsupportedUriSchemeIdentified(WebView sender, WebViewUnsupportedUriSchemeIdentifiedEventArgs args)
{
    args.Handled = true;

    // up to you what to do with args.Uri
}

Be aware that if the link is invalid, the WebView.NavigationFailed will be raised instead!

Upvotes: 2

Related Questions