简体   繁体   English

javascript-将js确认添加到mailto链接

[英]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? javascript是否有一种方法可以让页面自动查找任何mailto链接,然后在用户单击mailto链接时触发确认对话框?

From this site I found a way to do so for an alert. 从此站点,我找到了一种发出警报的方法。 I am beyond a novice with javascript. 我对javascript并不陌生。

We need to warn people not to include confidential information in the their email without having an existing relationship. 我们需要警告人们在没有现有关系的情况下不要在其电子邮件中包含机密信息。

HTML: HTML:

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

Javascript: Javascript:

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

There is a confirm function in javascript. javascript中有一个confirm功能。

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

Here is working demo 这是工作演示

try this: 尝试这个:

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

You can use javascript confirm dialog 您可以使用javascript确认对话框

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

您可以使其不使用jquery成为一个衬板:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM