Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I capture a navigation event in a webview on Windows 8?

I have a Webview in my app and I want to intercept any taps and open the links in IE rather than inside the Webview in the app.

I can only see NavigationFailed and LoadingComplete events, nothing regarding an "about to navigate" event which I could intercept.

like image 282
StarlitSkies Avatar asked Oct 01 '12 09:10

StarlitSkies


1 Answers

It seems there isn't any way to catch any navigation events. However, you can intercept script events called in JavaScript with window.external.notify()

Assuming the page is something you're hosting yourself, you can replace

<a href="http://www.lightwoodgames.com">LINK</a>

With

<a href="javascript:window.external.notify('http://www.lightwoodgames.com')">LINK</a>

Then in your project you'll want to add

webview.ScriptNotify += webview_ScriptNotify;
webview.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;

protected async void webview_ScriptNotify(object sender, NotifyEventArgs e)
{
  await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Value));
}
like image 156
StarlitSkies Avatar answered Sep 25 '22 18:09

StarlitSkies