Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
There is a function which send an email via default email client. In body of email message, there are few tabs between words. But, when I send this message to default email client(Outlook Express 6.0), these tabs are not present.

JavaScript Code:

JavaScript
function SendMail() {
        try {
             var mailAddress = 'test@gmail.com';
             var mailSubject = 'Mail Subject';
         var mailBody = 'Text   goes    here';
         location.href = 'mailto:' + encodeURIComponent(mailAddress) +
                '?subject=' + encodeURIComponent(mailSubject) +
                '&body=' + encodeURIComponent(mailBody);
            }
            catch (err) { alert(err);} 
        }


Test Output: Text goes here But, there should be tab instead of space between words. Anybody, help me what's wrong with this ?
Posted
Comments
Matt T Heffron 28-Jun-13 13:43pm    
Have you verified what is actually SENT to the email client here?
(I.e., what is the result of encodeURIComponent(mailBody) ?)
Are the Tab characters encoded?
If so, it seems that the issue is with the client's processing of the tabs when it gets the email body.
Itz.Irshad 1-Jul-13 7:07am    
I've tested, tabs characters are encoded correctly, but it is displayed on client program then empty spaces are eliminated.

Its probably displaying as HTML in the viewer. That means that tabs and multiple spaces are ignored. In order to get around this, try surrounding your body with <pre> and </pre> tags, like:

var mailBody = '<pre>Text goes here</pre>';
 
Share this answer
 
Comments
Itz.Irshad 28-Jun-13 9:23am    
Its not working. You can check it http://jsfiddle.net/irshad_mughal/5Zrqj/
Multiple spaces are neglected while rendering HTML. Instead use
HTML
, <p></p>
or any other HTML construct
 
Share this answer
 
Multiple spaces are neglected while rendering HTML. Instead use
HTML
, <p> ,   </p>
or any other HTML construct
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900