Search code examples
javascriptjqueryhtmlmailtoconfirm

javascript - add a js confirm to mailto link


Is there a way with javascript to automatically have the page look for any mailto links and then have it fire off an confirm dialog when a user clicks on the mailto link?

From this site I found a way to do so for an alert. I am beyond a novice with javascript.

We need to warn people not to include confidential information in the their email without having an existing relationship.

HTML:

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

Javascript:

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

Solution

  • Here is working demo

    try this:

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