残念ながら、WindowsPhoneのコントロールではサポートされていませんmailto:
。tel:
WebBrowser
できることは、すべてのa
タグを列挙してonclick
イベントを接続するJavascriptをHTMLに挿入することです。そのイベントが呼び出さwindow.external.Notify
れ、URLがパラメータとして、のScriptNotify
イベントが発生します。WebBrowser
少し複雑ですが、WindowsPhoneでこれらの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();
}
}
}