原理:如果成功会触发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

作者 铁血 汉子 2018年8月2日
2024/11/21/06:31:51pm 2018/8/2/10:05:36
0 2024