15

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 (ea. gmail as default client in macosx). What would be the best way to gracefully offer a fallback, kindly asking the user to manually email you? I could use JS or css to show a message once the link has been clicked:

submit was successful, or if nothing happened please email us manually.

What about using a form with mailto, can I use a redirect page upon success without or with serverside scripting? Is there a way to filter out the success from failure, instead of relying on the user's judgement with the double success/failed message above?

edit: At least what would be the most suitable way of changing a state when a mailto link (or form) has been clicked. Obviously JavaScript or css are options, but can't I simply create a double action link or form submit; mailto and also link to another page (you have submitted/clicked the button')

Mrigank Pawagi
  • 892
  • 1
  • 8
  • 26
newnomad
  • 1,055
  • 3
  • 11
  • 15
  • 4
    `mailto:` is bad - trust me, nobody likes opening e-mail client without reason. Use server-side form instead :). – Konrad Borowski Aug 27 '11 at 12:56
  • 1
    You can't tell anything about whether a "mailto:" link "works" for a user. – Pointy Aug 27 '11 at 13:00
  • Related: http://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers – DaveRandom Aug 27 '11 at 13:02
  • @xfix Since this is 1/2 questions on SO re. mailto loading failure, let me fix that for you: nobody likes opening the unused desktop email client without reason. We've come a long way since '11: http://webintents.org/faq.html -- Unfortunately, as far as I can tell... that long way doesn't include a failure event.... – Cory Mawhorter Jul 24 '14 at 22:06
  • Server-side forms are not ideal, as they can be abused. What we do is that we open up the mailto, and also display a dialog box with a gmail link. Not ideal, but it seems to be the best compromise. (This is for an invite button). – CpnCrunch Feb 03 '17 at 23:30

3 Answers3

14

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. Here's a JavaScript/jQuery example, simplified from the article.

(function($)) {
  $('a[href^=mailto]').each(function() {
    $(this).click(function() {
      var t;

      $(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);
Bluu
  • 5,226
  • 4
  • 29
  • 34
3

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.

Jules
  • 7,148
  • 6
  • 26
  • 50
  • 1
    I have good reasons for wanting to use the mailto link, and am familiar with the best practice for contact forms. I am more interested in getting a state change upon clicking (see edit question) – newnomad Aug 29 '11 at 04:45
-2

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

Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114
  • Or just a checkbox if the mailto is in the form of an action in a form. Guess it's a UI decision on when you want to bother the user thinking about it, before or after the click... – newnomad Aug 30 '11 at 05:28
  • 1
    Yes, I have email set up, I just type gmail in my browser… Don't assume users will understand that question (and [don't](http://w3fools.com/) recommend W3Schools as a reference) – Quentin Aug 30 '11 at 05:31
  • another approach is just offer a readible, copyable email address next to the link; http://stackoverflow.com/questions/6028471/mailto-with-no-default-email-client – newnomad Aug 30 '11 at 05:35