How do I capture a navigation event in a webview on Windows 8?(如何在 Windows 8 上的 web 视图中捕获导航事件?)
问题描述
我的应用中有一个 Webview,我想拦截任何点击并在 IE 中打开链接,而不是在应用的 Webview 中打开.
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.
我只能看到 NavigationFailed 和 LoadingComplete 事件,没有关于我可以拦截的即将导航"事件.
I can only see NavigationFailed and LoadingComplete events, nothing regarding an "about to navigate" event which I could intercept.
推荐答案
似乎没有任何方法可以捕获任何导航事件.但是,您可以使用 window.external.notify() 拦截在 JavaScript 中调用的脚本事件
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>
有
<a href="javascript:window.external.notify('http://www.lightwoodgames.com')">LINK</a>
然后在你的项目中添加
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));
}
这篇关于如何在 Windows 8 上的 web 视图中捕获导航事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Windows 8 上的 web 视图中捕获导航事件?


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01