原理:如果成功会触发window的blur事件

(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);

参考链接:https://www.uncinc.nl/en/articles/dealing-mailto-links-if-no-mail-client-available

作者 铁血 汉子 18 天前
2018/08/20/12:38:26am 2018/8/2/10:05:36
0 44