mailto fails in IE where there is a long body text. Is there any way to resolve this?
I am having a problem using Internet Explorer 8 (IE8) to open mailto links wit开发者_Go百科h long messages.
After the user clicks on the link, IE changes to an about:blank page and never completes the call to outlook to create an email
Here's an example:
<a href="mailto:name@name.com?subject=123456789&body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111">mailto fails in IE8</a>
If I shorten the list of 1's, the email is generated and can be sent.
Is this a known IE issue? What are the limitations?
I never could get the location.href = mailtoHref
hack to work. However, I have found that following works.
$('body').append($('<iframe id="mailtoHack" src="' + mailtoHref + '"/>');
$('#mailtoHack').remove();
EDIT
Here is a way to do it without jQuery:
function mailtoHack(href) {
var iframeHack;
if (href.indexOf("mailto:") === 0) {
iframeHack = document.createElement("IFRAME");
iframeHack.src = href;
document.body.appendChild(iframeHack);
document.body.removeChild(iframeHack);
}
}
And, for good measure, here is a Knockout custom binding usable as data-bind="mailto: foo"
:
ko.bindingHandlers.mailto = {
init: function (element, valueAccessor) {
ko.utils.registerEventHandler(element, "click", function (e) {
var href = ko.unwrap(valueAccessor()), iframeHack;
if (href.indexOf("mailto:") === 0) {
iframeHack = document.createElement("IFRAME");
document.body.appendChild(iframeHack);
document.body.removeChild(iframeHack);
} else {
e.preventDefault();
}
});
}
};
I too ran into this problem with IE8. Amazing that this is happening; it seems like a problem we'd have run into circa 1998!
Anyway, I did some testing and came up with a workaround that uses Javascript:
<a href="javascript:doMailto()">Send Email</a>
Then define this script:
<script type="text/javascript">
var sMailto = "mailto:name@name.com?subject=123456789&body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111234567890";
function doMailto() {
document.location.href = sMailto;
}
</script>
For whatever reason, IE has no problem "forwarding" to long URLs (my testing scenario uses 800+ characters). In cases with multiple mailto
links, you could define multiple URL variables and send a parameter into doMailto()
that lets it switch to the appropriate one.
Is it ugly? You bet. But it works in a pinch.
My advice would be to stop abusing the poor mailto link. If you want to prepopulate that much information, build a contact form for the user.
I also tried with the solution CBono posted but I coudn't make it work either. I found that when you directly paste the mailto URL in the browser it has no problem no matter how long the string is. So, I implemented something like this:
<a href ="#" onclick="javascript:doMailto(); return false;">Send Email</a>
<script type="text/javascript">
var sMailto = "mailto:mail@something.com;mail@something.com;mail@something.com?subject=A really long subject can go here if you want and it will work Im telling you&body=Click for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profileClick for detailed profile&cc= &bcc= mail@something.com";
function doMailto() {
window.open(sMailto);
}
</script>
As CBono mentioned, if you want this to be dynamic, you just need to pass the mailto string as parameter to the function and assing it to the sMailto variable.
Hope this helps.
it appears that the following hyperlink seems to work. It is 512 characters long and seems to work every time. You can increase the length of the To, but you must subtract either from subject or body. Same with subject.
I wish this was documented somewhere; I am just guessing from experimenting with this.
<a href="mailto:name@name.com?subject=123456789&body=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111234">
I will gladly accept any answer from a person that can track down documentation that indicates that this is a known issue.
精彩评论