detecting when mailto failed

后端 未结 3 748
暗喜
暗喜 2021-02-04 09:43

When using a mailto link chances are that it doesn\'t do anything for the user if he doesn\'t have an email client setup, or didn\'t setup his webmail to be his default client (

相关标签:
3条回答
  • 2021-02-04 09:58

    Use a JavaScript confirm popup to ask the user if they have email setup on their computer.

    0 讨论(0)
  • 2021-02-04 10:16

    You cannot detect whether or not a user has an email client setup. So I would suggest you to setup a server-side form for the user to contact you.

    Beneath or above this you can provide the user a link explaining him that if he wants to contact you directly through his main e-mail account, he can click this link (this link being a mailto: link).

    By providing him two ways of contacting you (webform or e-mail client), you give the user the opportunity to choose which one he wants to use. So it's up to him to realize whether or not he has an e-mail client installed and whether or not he wants to use it.

    0 讨论(0)
  • 2021-02-04 10:21

    This article discusses a hack of checking if the window's blur event fired after clicking the mailto. It uses a timeout, so it's not foolproof, but might address most cases.

    (function($)) {
      $('a[href^=mailto]').each(function() {
        var href = $(this).attr('href');
        $(this).click(function() {
          var t;
          var self = $(this);
    
          $(window).blur(function() {
            // The browser apparently responded, so stop the timeout.
            clearTimeout(t);
          });
    
          t = setTimeout(function() {
            // The browser did not respond after 500ms, so open an alternative URL.
            document.location.href = '...';
          }, 500);
        });
      });
    })(jQuery);
    
    0 讨论(0)
提交回复
热议问题