【问题标题】:How can I get this email function to work?我怎样才能让这个电子邮件功能工作?
【发布时间】:2011-06-30 13:33:53
【问题描述】:

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

【问题讨论】:

  • 值得注意的是,IE7默认禁用prompt()。

标签: javascript jquery email jquery-events


【解决方案1】:

覆盖取消按钮和一个空白字符串,以防有人试图这样做以取消。

if(subject && subject != "") {
    document.location = "mailto:" + email + "?subject=" + escape(subject) + "&body=" + escape(emailme.selection);
}

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

【讨论】:

  • 您可能需要缓存刷新页面以确保加载更改。
【解决方案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);
            }
        }},

【讨论】:

  • 完美,无畏。感谢您的宝贵时间,先生。
  • @patrick dw:一定是 Stackoverflow 的滞后,代码示例最初不存在 - 哈哈
猜你喜欢
  • 2013-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-12
  • 1970-01-01
相关资源
最近更新 更多