代码之家  ›  专栏  ›  技术社区  ›  HyderA

绕过mailto/ref/url字符限制

  •  9
  • HyderA  · 技术社区  · 15 年前

    我在锚标签中有一个邮件链接

    <a href="mailto:?subject=Subject&body=Body">Email This</a>
    

    问题是Body参数是一篇很大的文章,url上似乎有字符限制。

    有办法绕过这个限制吗?

    4 回复  |  直到 15 年前
        1
  •  10
  •   Pekka    15 年前

    有办法绕过这个限制吗?

    很难。

    甚至有可能不同浏览器或电子邮件客户端的限制也有所不同。

        2
  •  6
  •   Guffa    15 年前

    是的,URL的长度有限制。

    Internet Explorer似乎是具有最短限制的浏览器。根据 this article 有2083个字符。

        3
  •  0
  •   Yash Vyas    14 年前

    是的,Mailto标签有问题,它因浏览器和电子邮件客户端而异 给客户发邮件。如果出现此问题,请尝试服务器端脚本来解决此问题。邮递员有时表现得很不正常

        4
  •  -1
  •   Nick    8 年前

    我知道这个问题已经过时了,但我也遇到了类似的问题,达到了将电子邮件发送给许多收件人的极限。

    我碰到这个 solution ,但我不明白为什么,我还是把它留在这里

    function sendEmails(emails) {
      var timeout = 2000;
      var mailtoPrefix = 'mailto:?bcc=';
      var maxUrlCharacters = 1900;
      var separator = ';';
      var currentIndex = 0;
      var nextIndex = 0;
    
      if (emails.length < maxUrlCharacters) {
        window.location = mailtoPrefix + emails;
        return;
      }
    
      do {
        currentIndex = nextIndex;
        nextIndex = emails.indexOf(separator, currentIndex + 1);
      } while (nextIndex != -1 && nextIndex < maxUrlCharacters)
    
      if (currentIndex == -1) {
        window.location = mailtoPrefix + emails;
      } else {
        window.location = mailtoPrefix + emails.slice(0, currentIndex);
        setTimeout(function () {
          sendEmails(emails.slice(currentIndex + 1));
        }, timeout);
      }
    }
    

    用法:

    var emails = 'a@a.com;b@b.com;c@c.com';
    sendEmails(emails);
    
    推荐文章