Question

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');
});
Was it helpful?

Solution 2

Here is working demo

try this:

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

OTHER TIPS

There is a confirm function in javascript.

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

You can use javascript confirm dialog

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

you can make it a one liner without jquery:

<a href="mailto:name@domain.com" onclick="return confirm('Are you sure?')">Email Link</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top