【问题标题】:javascript - add a js confirm to mailto linkjavascript - 向 mailto 链接添加 js 确认
【发布时间】:2014-01-04 18:19:04
【问题描述】:

javascript 有没有办法让页面自动查找任何 mailto 链接,然后在用户点击 mailto 链接时触发确认对话框?

从这个网站我找到了一种方法来发出警报。我不是 javascript 的新手。

我们需要警告人们不要在没有现有关系的情况下在他们的电子邮件中包含机密信息。

HTML:

<a href="mailto:name@domain.com">Email Link</a>

Javascript:

$('a[href^="mailto"]').on('click',
function() {
alert('This is some alert text');
});

【问题讨论】:

    标签: javascript jquery html mailto confirm


    【解决方案1】:

    javascript中有一个confirm函数。

    $('a[href^="mailto"]').on('click',
    function() {
      if (!(confirm('This is some alert text'))) {
         return false;
      }
    });
    

    【讨论】:

      【解决方案2】:

      Here is working demo

      试试这个:

      $('a[href^="mailto"]').on('click',
      function() {
        return confirm('Do you want to send email?');
      });
      

      【讨论】:

        【解决方案3】:

        您可以使用 javascript 确认对话框

        $('a[href^="mailto"]').on('click', function() {
            return confirm('your question');
        });
        

        【讨论】:

        • 文字确认后无需提醒。
        【解决方案4】:

        您可以在没有 jquery 的情况下使其成为单行:

        <a href="mailto:name@domain.com" onclick="return confirm('Are you sure?')">Email Link</a>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-08
          • 2010-09-10
          • 2014-08-29
          • 1970-01-01
          • 2017-07-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多