1

无论如何,我可以通过 Metro 中的超链接值在 webview 中单击我的 c# 中的超链接吗?我正在使用 WebView..NavigateToString() 来生成内容?

4

2 回答 2

5

您可以InvokeScript使用自己的一些 Javascript 调用来设置侦听器,以便在用户离开您的页面时进行监听。这在 C# 中类似于以下内容:

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

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

然后您可以使用ScriptNotify监听您的特定消息来确定页面正在卸载并且用户正在离开。不幸的是,您无法检测到用户的去向。此外,如果超链接在新窗口中打开并且 web 视图未卸载,您也无法检测到。

于 2012-09-21T19:49:22.410 回答
1

Since WebView in windows 8 doesn't support Navigating() events like the Silverlight WebBrowser control, thus it is not possible to get hyperlink or cancel navigation.

But since you're using NavigateToString() method, you can write some manual javascript code and achieve same with the help of WebView.ScriptNotify() event.

于 2012-07-12T08:20:48.877 回答