Html 电子邮件地址中包含 & 符号的 mailto 链接有问题吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9498225/
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
Issue with mailto link in email address containing ampersand?
提问by sushil bharwani
I have a mailto link like that <a href="mailto:a&[email protected]" >
it displays correctly on html but when we click on the link the outlook just shows a in the to address. Has anyone faced the same problem please suggest.
我有一个类似的 mailto 链接,<a href="mailto:a&[email protected]" >
它可以在 html 上正确显示,但是当我们单击该链接时,Outlook 只在 to 地址中显示一个。有没有人遇到过同样的问题,请提出建议。
回答by Pekka
Percent encodingthe string is required for IE and I assume will work across browsers. From this MSDN document:
IE 需要对字符串进行百分比编码,我认为可以跨浏览器工作。从 这个 MSDN 文档:
Windows Internet Explorer 7 and later. You must percent-encode all URL-reserved characters within a mailto: address. For example, the number sign (#) is used as a fragment identifier in URLs. When processing an address such as some#[email protected], Internet Explorer copies only the portion up to the number sign into the mail client; the fragment portion including the number sign is ignored. This behavior is by design.
Windows Internet Explorer 7 及更高版本。您必须对 mailto: 地址中的所有 URL 保留字符进行百分比编码。例如,数字符号 (#) 在 URL 中用作片段标识符。在处理诸如 some#[email protected] 之类的地址时,Internet Explorer 仅将数字符号之前的部分复制到邮件客户端;包含数字符号的片段部分将被忽略。此行为是设计使然。
So you need
所以你需要
<a href="mailto:a%26b_admin%40xyz.com">
As said, I expect a percent encoded address will work in all browsers, but I don't know for sure. I can confirm it works with Chrome and Thunderbird.
如上所述,我希望百分比编码的地址适用于所有浏览器,但我不确定。我可以确认它适用于 Chrome 和 Thunderbird。