开发者

Using Javascript mailto and getting errors when url is >600 characters

My method for sending an email works pretty much like this,

function sendMail() 
{     
  var link = "mailto:me@example.com"              
  + "?cc=myCCaddress@example.com"              
  + "&subject=" + escape("This is my subject")              
  + "&body=" + escape(document.getElementById('myText').value);      

  window.location.href = link; 
} 

I'm us开发者_如何学JAVAing alert(link.length) and anytime it goes over about 620 characters, the IE tab 'crashes', it gives the "This tab has been recovered" message, but does not actually recover very well at all.

What's up with that?


There seems to be a limit according to this. I can't test the following as I only have access to a Mac at the moment, but have you tried this:

function sendMail() 
{     
    var mailForm = document.createElement('form');
    mailForm.id = 'mailForm';
    mailForm.action = 'mailto:user@mailinator.com';
    mailForm.method = 'get';

    var cc = document.createElement('input');
    cc.name = 'cc';
    cc.type = 'hidden';
    cc.value = 'ccUser@mailinator.com';

    var subject = document.createElement('input');
    subject.name = 'subject';
    subject.type = 'hidden';
    subject.value = escape("This is my subject");

    var msgBody = document.createElement('input');
    msgBody.name = 'body';
    msgBody.type = 'hidden';
    msgBody.value = escape(document.getElementById('myText').value);

    mailForm.appendChild(cc);
    mailForm.appendChild(subject);
    mailForm.appendChild(msgBody);
    document.body.appendChild(mailForm);
    document.forms['mailForm'].submit();
}

See demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜