想要在WP7的外部浏览器中打开链接
架构如下:
单击按钮后,将打开一个 HTML 页面,其中包含一个链接。单击链接后,我想在 WP7 的外部(默认)浏览器中打开它,以便应用程序关闭并在外部打开链接。我该如何实现这个?
在 xaml 文件中添加了此控件:
<phone:WebBrowser Name="browser" Margin="0,78,0,0" />
单击按钮时:
private void Information_Loaded(Object sender,RoutedEventArgs e)
{
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("index_en.html"))
{
using (StreamReader reader = new StreamReader(stream))
{
string html = reader.ReadToEnd();
browser.NavigateToString(html);
}
}
现在 index_en.html 有一个要在外部浏览器中打开的链接。
The architecture is like:
On click of a button an HTML page opens which contains a link in it. On clicking the links I want to open it in external (default) browser of WP7 such that the application closes and link opens externally. How can I implement this?
Added this control in xaml file:
<phone:WebBrowser Name="browser" Margin="0,78,0,0" />
On button click:
private void Information_Loaded(Object sender,RoutedEventArgs e)
{
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("index_en.html"))
{
using (StreamReader reader = new StreamReader(stream))
{
string html = reader.ReadToEnd();
browser.NavigateToString(html);
}
}
Now index_en.html has a link which is to be opened in external browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常,您可以使用
标记上的
Target
属性来执行此操作。但是,在 WP7 中(至少在模拟器中),这不起作用。您可以做的是使用
Navigating
事件进行拦截,如下所示:Normally, you would do so using
Target
property on<a>
tag. But, inWP7
(at least in Emulator), this does not work.What you could do is intercept using
Navigating
event something like following:您可以使用
WebBrowserTask
启动浏览器。我发现你需要转义你传递给它的 URL:(
You can use the
WebBrowserTask
to launch the browser.I've found that you need to escape the URL you pass to it though :(
你可以使用类似的东西
You can use something like that