views:

48

answers:

1

Here are some strings that I'm using to ultimately form a HTML mailto link. I'm doing this in javascript. If I output the mailtoString to an alert() I get the link looks just fine. However, when I put it into the location.href the string is cut short at the "&" character. How do I tell the location.href that the "&" is not the end of the mailto link?

    var subject = escape('subject');
    var body = escape('body');
    var reportUrl = document.URL + "/GetUpdatedTableResults?beginDate=" + beginDate + "&endDate=" + endDate + "&fileId=" + DocId + '&languageCode=' + LangCode + '&documentResultType=' + result + '&result=' + ReportedIssue;
    var excelUrl = document.URL + 'CurReport/GetCSVReport?beginDate=' + beginDate + '&endDate=' + endDate + '&fileId=' + DocId + '&languageCode=' + LangCode + '&documentResultType=' + result + '&result=' + ReportedIssue;
    var mailtoString = 'mailto:?subject=' + subject + '&body=' + body + '%0A%0AWeb:%0A' + reportUrl + '%0A%0AExcel:%0A' + excelUrl;        
    location.href = mailtoString;

After running the code above I get the following output.

http://localhost:5050/CurReport/GetUpdatedTableResults?beginDate=0 
+1  A: 

Because immediately after mailto: should be the email address. ? is a valid email characters but & is not. Anyway, the & should be escaped to &.

Coronatus
Yes, the email address should come after the `mailto:` but I just want outlook (or default) to open a new email with the "to" field blank.
Aaron Salazar
Did you encode the ampersand? Different email programs have their own restrictions on what fields you can preset. I would your version of Outlook won't allow the body to be preset.
Coronatus