How can I get this email function to work?
The way this is written now, the email prompt opens, but when I click cancel, my default email program opens anyway. How can I re-write this to return null or false, so that when I click cancel, the default email program doesn't open?
{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);
}},
You should verify is subject is not null, and change the location only if it is not.
{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);
}
}},
Cover the cancel button & a blank string incase someone tries to do this to cancel.
if(subject && subject != "") {
document.location = "mailto:" + email + "?subject=" + escape(subject) + "&body=" + escape(emailme.selection);
}
UPDATE: Example: http://blog.bmn.name/so-test
精彩评论