Getting around mailto / href / url character limit

做~自己de王妃 提交于 2019-11-27 17:46:45

问题


I have a mailto link in an anchor tag

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

The issue is that the Body parameter is a huge article, and there appears to be a character limit on the url.

Is there a way to get around the limit?


回答1:


Is there a way to get around the limit?

Very hardly.

It is even probable that the limitations vary from browser to browser, or from E-Mail client to E-Mail client.

I would rather use a HTML form and a server-side script to send the message.




回答2:


Yes, there is a limit on the length of the URL.

The limit varies from browser to browser, so you should keep the URL below 2000 characters to be safe.

Internet Explorer seems to be the browser that is having the shortest limit. According to this article it's 2083 characters.




回答3:


Yes there are issues with Mailto tag it varies from browser to browser and email client to email client . In case of this issues try server side script to overcome this issue . Mailto at times behaves very abnormal




回答4:


I know this question is old, but I had a similar problem, hitting the limit as I needed to send the email into many recipients.

I came across this solution, but I don't understand why it works, I leave it here anyway

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

usage:

var emails = 'a@a.com;b@b.com;c@c.com';
sendEmails(emails);


来源:https://stackoverflow.com/questions/4067391/getting-around-mailto-href-url-character-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!