如何才能使此电子邮件功能正常工作?

时间:2011-02-19 23:28:35

标签: javascript jquery email javascript-events

现在写入的方式,电子邮件提示打开,但是当我单击取消时,我的默认电子邮件程序仍会打开。如何重新编写此函数以返回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);
    }},

2 个答案:

答案 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);
}

更新:示例:http://blog.bmn.name/so-test