Windows phone 7 网络浏览器windows phone+;电话和邮寄标签don';行不通
我正在使用webbrowder呈现html字符串Windows phone 7 网络浏览器windows phone+;电话和邮寄标签don';行不通,windows-phone-7,xaml,webbrowser-control,windows-phone-8,Windows Phone 7,Xaml,Webbrowser Control,Windows Phone 8,我正在使用webbrowder呈现html字符串 private void webBrowserHTML_Loaded(object sender, RoutedEventArgs e) { WebBrowser web = sender as WebBrowser; string description = web.DataContext.ToString(); web.NavigateToString(d
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没有打开
有什么解决方案吗?不幸的是,Windows Phone上的
WebBrowser
控件不支持mailto:
和tel:
您可以做的是在HTML中插入Javascript,它将枚举所有a
标记,并连接一个onclick
事件。该事件将调用window.external.Notify
,这将依次引发WebBrowser
的ScriptNotify
事件,URL作为参数
这有点复杂,但我认为这是在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();
}
}
}
//构造函数
公共主页()
{
初始化组件();
browser.isscript enabled=true;
browser.ScriptNotify+=浏览器\脚本通知;
browser.Loaded+=已加载的浏览器;
}
已加载无效浏览器(对象发送器,路由目标)
{
//示例HTML代码
字符串html=@“;
//将调用的脚本通过window.external.Notify引发ScriptNotify
字符串notifyJS=@”
window.onload=函数(){
var links=document.getElementsByTagName('a');
对于(var i=0;iGreat fix,上述解决方案效果更好,
<onclick="window.location.href = 'tel:1231231234';">
而不是
<a href="tel:+33102030405">
谢谢
你真的必须使用WebBubl控件吗?为什么不在点击事件中使用带有EnguleCytoTeq和PooCeLeCu饰的按钮?我调用返回HTML的WebService,这就是为什么我需要使用WebBuffSert这不是一个答案,考虑添加注释。