admin管理员组文章数量:1026114
I have to sent a confirmation email to the users. and on clicking of a link, i want to open their default email client and add a HTML into the body tag.
var subject = Your transaction No: +': ' + $('#confirmationNumber').text()+ ' is confirmed';
var emailBody = $('#confirmation').html();
$(this).attr('href','mailto:'+userEmail+'&subject=' + subject +'&body='+ emailBody);
it want the HTML in 'emailBody' to get appended to the body as HTML. But it displays me the entire HTML tags instead.
Is there a way i can append a HTML in the body ?
I have to sent a confirmation email to the users. and on clicking of a link, i want to open their default email client and add a HTML into the body tag.
var subject = Your transaction No: +': ' + $('#confirmationNumber').text()+ ' is confirmed';
var emailBody = $('#confirmation').html();
$(this).attr('href','mailto:'+userEmail+'&subject=' + subject +'&body='+ emailBody);
it want the HTML in 'emailBody' to get appended to the body as HTML. But it displays me the entire HTML tags instead.
Is there a way i can append a HTML in the body ?
Share Improve this question asked Jun 5, 2012 at 14:44 nipivnipiv 8532 gold badges9 silver badges21 bronze badges3 Answers
Reset to default 2The answer is short but unfortunate:
No.
When using mailto:
-links, you can only specify text, not HTML. Even if the user’s mail client poses a mail message using HTML, your body text will only be inserted as text.
There’s nothing you can do about that from a web page.
Use
var emailBody = $('#confirmation').text();
First of all, some fixes to your code:
var subject = 'Your transaction No: ' + $('#confirmationNumber').text() + ' is confirmed',
emailBody = $('#confirmation').html();
$(this).attr('href', 'mailto:' + userEmail + '&subject=' + subject + '&body=' + encodeURI(emailBody));
- Use single
var
keyword and separate variables with mas subject
was concatenated badly
Next, if you want to pass html code in link you have to encode special chars, which encodeURI()
does.
Oops, encoded body isn't treated as html in email client.. I googled for a while and it seems you can't pass it correctly, can't you send a message instead of opening client?
I have to sent a confirmation email to the users. and on clicking of a link, i want to open their default email client and add a HTML into the body tag.
var subject = Your transaction No: +': ' + $('#confirmationNumber').text()+ ' is confirmed';
var emailBody = $('#confirmation').html();
$(this).attr('href','mailto:'+userEmail+'&subject=' + subject +'&body='+ emailBody);
it want the HTML in 'emailBody' to get appended to the body as HTML. But it displays me the entire HTML tags instead.
Is there a way i can append a HTML in the body ?
I have to sent a confirmation email to the users. and on clicking of a link, i want to open their default email client and add a HTML into the body tag.
var subject = Your transaction No: +': ' + $('#confirmationNumber').text()+ ' is confirmed';
var emailBody = $('#confirmation').html();
$(this).attr('href','mailto:'+userEmail+'&subject=' + subject +'&body='+ emailBody);
it want the HTML in 'emailBody' to get appended to the body as HTML. But it displays me the entire HTML tags instead.
Is there a way i can append a HTML in the body ?
Share Improve this question asked Jun 5, 2012 at 14:44 nipivnipiv 8532 gold badges9 silver badges21 bronze badges3 Answers
Reset to default 2The answer is short but unfortunate:
No.
When using mailto:
-links, you can only specify text, not HTML. Even if the user’s mail client poses a mail message using HTML, your body text will only be inserted as text.
There’s nothing you can do about that from a web page.
Use
var emailBody = $('#confirmation').text();
First of all, some fixes to your code:
var subject = 'Your transaction No: ' + $('#confirmationNumber').text() + ' is confirmed',
emailBody = $('#confirmation').html();
$(this).attr('href', 'mailto:' + userEmail + '&subject=' + subject + '&body=' + encodeURI(emailBody));
- Use single
var
keyword and separate variables with mas subject
was concatenated badly
Next, if you want to pass html code in link you have to encode special chars, which encodeURI()
does.
Oops, encoded body isn't treated as html in email client.. I googled for a while and it seems you can't pass it correctly, can't you send a message instead of opening client?
本文标签: how to add html in a email body using javascriptStack Overflow
版权声明:本文标题:how to add html in a email body using javascript? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745624445a2159775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论