Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting when mailto failed

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')

like image 287
newnomad Avatar asked Aug 27 '11 12:08

newnomad


1 Answers

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);
like image 60
Bluu Avatar answered Oct 12 '22 07:10

Bluu