我正在使用一个网页浏览器来呈现一个html字符串。
private void webBrowserHTML_Loaded(object sender, RoutedEventArgs e)
{
WebBrowser web = sender as WebBrowser;
string description = web.DataContext.ToString();
web.NavigateToString(description);
}在这个html中,我有tel和mailto标记:
<a href="mailto:xxxx@xx.xx"> Envoyer un email </a>
<a href="tel:+33102030405"> Appeler la société xxx </a>我的问题是,当我点击号码,我不打电话,当我点击邮件是不能打开我的outlook!!
有什么解决办法吗?
发布于 2013-02-20 21:43:23
遗憾的是,Windows Phone上的WebBrowser控件不支持mailto:和tel:。
您可以做的是在HTML语言中注入Javascript,它将枚举所有的a标记并连接一个onclick事件。该事件将调用window.external.Notify,后者将以URL作为参数引发WebBrowser的ScriptNotify事件。
这有点复杂,但我认为这是在Windows Phone上处理这些mailto和tel协议的唯一选择。
代码如下:
// Constructor
public MainPage()
{
InitializeComponent();
browser.IsScriptEnabled = true;
browser.ScriptNotify += browser_ScriptNotify;
browser.Loaded += browser_Loaded;
}
void browser_Loaded(object sender, RoutedEventArgs e)
{
// Sample HTML code
string html = @"<html><head></head><body><a href='mailto:test@test.com'>Envoyer un email</a><a href='tel:+3301010101'>Appeler</a></body></html>";
// Script that will call raise the ScriptNotify via window.external.Notify
string notifyJS = @"<script type='text/javascript' language='javascript'>
window.onload = function() {
var links = document.getElementsByTagName('a');
for(var i=0;i<links.length;i++) {
links[i].onclick = function() {
window.external.Notify(this.href);
}
}
}
</script>";
// Inject the Javascript into the head section of the HTML document
html = html.Replace("<head>", string.Format("<head>{0}{1}", Environment.NewLine, notifyJS));
browser.NavigateToString(html);
}
void browser_ScriptNotify(object sender, NotifyEventArgs e)
{
if (!string.IsNullOrEmpty(e.Value))
{
string href = e.Value.ToLower();
if (href.StartsWith("mailto:"))
{
EmailComposeTask email = new EmailComposeTask();
email.To = href.Replace("mailto:", string.Empty);
email.Show();
}
else if (href.StartsWith("tel:"))
{
PhoneCallTask call = new PhoneCallTask();
call.PhoneNumber = href.Replace("tel:", string.Empty);
call.Show();
}
}
}发布于 2015-02-25 22:09:34
<onclick="window.location.href = 'tel:1231231234';">而不是
<a href="tel:+33102030405">谢谢
发布于 2013-03-07 16:01:28
很好的修复,上面的解决方案工作得更好,
https://stackoverflow.com/questions/14977347
复制相似问题