Html 绕过mailto / href / url字符限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4067391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting around mailto / href / url character limit
提问by HyderA
I have a mailto link in an anchor tag
我在锚标签中有一个 mailto 链接
<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.
问题是 Body 参数是一篇大文章,而且 url 似乎有字符限制。
Is there a way to get around the limit?
有没有办法绕过限制?
采纳答案by Pekka
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.
我宁愿使用 HTML 表单和服务器端脚本来发送消息。
回答by Guffa
Yes, there is a limit on the length of the URL.
是的,URL 的长度是有限制的。
The limit varies from browser to browser, so you should keep the URL below 2000 characters to be safe.
限制因浏览器而异,因此您应该将 URL 保持在 2000 个字符以下以确保安全。
Internet Explorer seems to be the browser that is having the shortest limit. According to this articleit's 2083 characters.
Internet Explorer 似乎是具有最短限制的浏览器。根据这篇文章,它是 2083 个字符。
回答by Yash Vyas
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
是的,Mailto 标签存在问题,它因浏览器而异,电子邮件客户端因电子邮件客户端而异。如果出现此问题,请尝试使用服务器端脚本来解决此问题。Mailto 有时表现得很不正常
回答by Nick
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 = '[email protected];[email protected];[email protected]';
sendEmails(emails);