xaml WebView:如何捕捉“OnNavigation"事件@Windows Store 应用程序 [英] xaml WebView: How to catch a "OnNavigation" event @Windows Store App

查看:24
本文介绍了xaml WebView:如何捕捉“OnNavigation"事件@Windows Store 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C#/xaml 开发 Windows 应用商店应用.

I am developing Windows Store Apps with C#/xaml.

我如何注意到我的 WebView 中的链接是否被点击?该 afaik 没有事件.我已经研究过 这个那个但它没有为我提供合适的解决方案.

How do I notice if a link in my WebView gets klicked? There is no Event for that afaik. I've already looked into this and that but it doesn't provide me with a suitable solution.

我可以举个例子:我通过 iFrame 将 facebook 页面的流嵌入到我的 WebView 中.我想阻止可能在该 iFrame 中的所有链接.

May I give an example: I am embedding the stream of a facebook page in my WebView via iFrame. I want to block all links that might be in that iFrame.

推荐答案

您可以使用自己的一些 Javascript 调用 InvokeScript 来设置当用户导航离开您的页面时的侦听器.这在 C# 中看起来类似于以下内容:

You can call InvokeScript with some of your own Javascript to set up a listener for when the user navigates away from your page. This would look something like the following in C#:

var navigationListenerString = @"
(function() {
  function leavingPage() {
    window.external.notify("LEAVING PAGE");
  }
  window.onbeforeunload = leavingPage;
})()";

webView.InvokeScript("eval", new string[] { navigationListenerString });

然后您可以使用 ScriptNotify 来监听您的特定消息,以确定页面正在卸载并且用户正在离开.不幸的是,您无法检测到用户要去哪里.此外,如果超链接在新窗口中打开并且 webview 没有卸载,您也无法检测到.

Then you can use ScriptNotify to listen for your particular message to determine that the page is unloading and the user is leaving. Unfortunately you cannot detect where a user is going. Also, if the hyperlink opens in a new window and the webview does not unload, you cannot detect that either.

这篇关于xaml WebView:如何捕捉“OnNavigation"事件@Windows Store 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆