现在写入的方式,电子邮件提示打开,但是当我单击取消时,我的默认电子邮件程序仍会打开。如何重新编写此函数以返回null或false,以便当我单击取消时,默认的电子邮件程序无法打开?提前谢谢!
{name: 'Email selection',
className: 'email',
beforeInsert: function(emailme) {
if (emailme.altKey) {
email = prompt("Email:");
} else {
email = "";
}
subject = prompt("Subject:", "Enter A Subject");
document.location = "mailto:" + email + "?subject=" + escape(subject) + "&body=" + escape(emailme.selection);
}},
答案 0 :(得分:2)
您应该验证主题是否为空,并且只有在不是时才更改位置。
{name: 'Email selection',
className: 'email',
beforeInsert: function(emailme) {
if (emailme.altKey) {
email = prompt("Email:");
} else {
email = "";
}
subject = prompt("Subject:", "Enter A Subject");
if (subject)
{
document.location = "mailto:" + email + "?subject=" + escape(subject) + "&body=" + escape(emailme.selection);
}
}},
答案 1 :(得分:2)
覆盖取消按钮&一个空白字符串,有人试图这样做取消。
if(subject && subject != "") {
document.location = "mailto:" + email + "?subject=" + escape(subject) + "&body=" + escape(emailme.selection);
}