2011-12-08 47 views
1

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

这里是锚标记:

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

这里是脚本:

var sMailto = "mailto:[email protected]?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)。我意识到它不是一个完美的解决方案,但它的作品

+0

我有同样的问题。似乎是sMailTo长度的问题。如果长度大于508个字符,则失败。 – BlackMael

+0

可能与Bookmarklet长度限制508也有关 – BlackMael

回答

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中的奇怪字符(或通常的代码)时比其他浏览器更轻松。

希望有帮助

+0

不幸的是,这不起作用,但我确实找到了解决这个问题的办法:如果你使用window.open(url)ie9的行为应该如此。感谢您的帮助,我最终使用该URL编码器。 –