2013-05-27 53 views
0

点击由WebView托管的html链接时,页面会在WebView内打开。我相信,如果你允许,微软将通过申请认证。Metro App WebView for html Hyperlink导航在浏览器中打开

因此,我如何获得WebView来检测本身内的导航,然后在浏览器中启动url?

+1

您可以通过设置'target ='_blank''来添加一个JavaScript,它可以调整所有的超链接。在webview加载后调用该javascript。 – Xyroid

+0

我该如何去做? – c0D3l0g1c

回答

0

感谢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); 
     } 
相关问题