IE9和mailto字符限制

时间:2011-12-08 09:59:12

标签: html internet-explorer-9

我尝试使用mailto和href发送预先填充的电子邮件但是我很快发现IE9在识别长度超过509字符(给予或接受)的href时出现问题。基本上,点击链接会显示一个空白页面。我寻找答案并遇到了这个javascript解决方案,但它仍然无法正常工作。

这是锚标记:

<a href="javascript:doMailto()">Sign up</a>

以下是剧本:

var sMailto = "mailto:blah@email.com?body=Dear eyecare professional,%0A%0aTo help us schedule your upcoming webinar, please fill out and return the following information:%0A%0A•  Name:%0A%0A•  Preferred date of webinar* (any Wednesday at 6 pm EST):%0A%0A•  City/State (Optional):%0A%0A•  Comments/Questions/Feedback:%0A%0AUpon receipt, we will send you a link to an upcoming GoTo Meeting webinar on Macula Risk implementation in your clinic. These webinars are regularly held on Wednesdays at 6 pm EST.%0A%0A* If you would like to request training on any other date or time - please note this in the Comments section and we will do our best to accommodate your request.%0A%0AKind Regards,%0A%0AGerry Bruckheimer";

   function doMailto() {
      document.location.href= sMailto;
   }

奇怪的是,除了愚蠢的IE 9之外,其他所有浏览器都可以使用。

更新:如果您遇到与我类似的问题,请尝试使用window.open(url)。我意识到它不是一个完美的解决方案,但它确实有效。

1 个答案:

答案 0 :(得分:1)

在跟踪链接时,IE9的URL限制实际上在between 5120 and 5150处非常高。不幸的是,Javascript黑客在这里没有帮助 - 限制仍然有效。我怀疑这是个问题。

您发送的邮件包含一些我不会放入网址的字符,尤其是“•”。您应该在将消息放入链接之前对其进行URL编码(最后一个符号显然编码为%e2%80%a2)。在将其粘贴到<a>标记之前,您可以URL encode it in Javascriptmanually encode it with an online tool

有些浏览器在处理URL中的奇怪字符(或一般代码中)时比其他浏览器更放松。

希望有所帮助