1

Webブラウザを使用して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>

番号をクリックしたとき、電話をかけなかったとき、メールをクリックしたときの問題は、私の見通しを開いていません!!

解決策はありますか?

4

3 に答える 3

1

残念ながら、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();
            }
        }
    }
于 2013-02-20T13:43:23.247 に答える
1
<onclick="window.location.href = 'tel:1231231234';">

それ以外の

<a href="tel:+33102030405">

ありがとう

于 2015-02-25T14:09:33.537 に答える
0

すばらしい修正です。上記のソリューションの方がはるかに効果的です。

于 2013-03-07T08:01:27.780 に答える