【问题标题】:Metro App WebView for html Hyperlink Navigation to open in browserMetro App WebView 用于 html 超链接导航以在浏览器中打开
【发布时间】:2013-06-05 03:21:35
【问题描述】:

单击WebView 托管的html 中的超链接时,页面将在WebView 中打开。我相信,如果您允许,Microsoft 将无法通过应用程序认证。

因此,我如何让WebView 检测自身内部的导航,然后在浏览器中启动该 url?

【问题讨论】:

  • 您可以通过设置target = '_blank' 添加一个调整所有超链接的JavaScript。加载 webview 后调用该 javascript。
  • 我该怎么做?

标签: windows-runtime microsoft-metro winrt-xaml c#-5.0


【解决方案1】:

感谢 Xyroid 的提示。这就是我最终要做的:

        /// <summary>
        /// Regex pattern for getting href links.
        /// </summary>
        private static readonly Regex HrefRegex = new Regex("href=\"([^\"]*)\"", RegexOptions.IgnoreCase);

        // Append target="_blank" to all hrefs
        html = HrefRegex.Replace(html, new MatchEvaluator(HrefReplace));

        /// <summary>
        /// Replaces the contents of href with href and target.
        /// </summary>
        /// <param name="match">The match.</param>
        /// <returns>The href with target.</returns>
        private static string HrefReplace(Match match)
        {
            return string.Format("{0} target=\"_blank\"", match.Value);
        }

【讨论】:

    猜你喜欢
    • 2015-11-01
    • 1970-01-01
    • 2017-05-13
    • 2014-07-12
    • 2018-02-11
    • 2014-03-12
    • 2017-08-06
    • 1970-01-01
    • 2021-09-23
    相关资源
    最近更新 更多