0

All,

I am not very familiar with javascript. However, using the following code I can successfully open, output to a new browser page, and print the contents of webpart. This part works as needed. With that the script will also open a new outlook email. I need the same content that is displayed to the web page output to the body of the email. Is this possible?

<p align="center"><input id="printpagebutton" 
onclick="printpage()"     type="button" value="Print Mail"/> </p>

<script type="text/javascript">

function sendmail()
{
var link = "mailto:me@me.com"
         + "?cc=you@me.com"
         + "&subject=" + escape("Help Me")
     + "&body=" + escape()
;

window.location.href = link;
}
function printpage()
{
var patt = /WebPartWPQ2/g;
var alldivs = document.getElementsByTagName('div');
var printpageHTML = '';
for(var i=0; i<alldivs.length; i++){
  if(patt.test(alldivs[i].id)){
printpageHTML = '<HTML><HEAD>\n' +
  document.getElementsByTagName('HEAD')[0].innerHTML +
  '</HEAD>\n<BODY>\n' + 
  alldivs[i].innerHTML.replace('inline-block','block') + 
  '\n</BODY></HTML>';
break;
}
}
var printWindow = window.open('','printWindow');
printWindow.document.open();
printWindow.document.write(printpageHTML);
sendmail()

}
</script>
  • Would you drive a race car in the I-500 if you have never learned how to drive? Same applies to your question; you first have to learn about HTML Entities before you can apply them – Danny '365CSI' Engelman Mar 29 '17 at 10:13
0

You will see the same HTML code in the new email window body. So we will pass only plain text and some special characters (new line, tab and etc...) in URL encoding format.

The URL encoding special characters can be referred from the following link

https://www.w3schools.com/tags/ref_urlencode.asp

Let me know if you need additional info on this.

  • Venkat, thank you for your response however I am not understanding what you are suggesting. I am not trying to get the URL from the webpage. I need the content data displayed on the webpage also displayed in the body of the email. The recipients of the email will not be able to open a URL or link. They'll need to see the data in the email body. – TOE_CHEESE Mar 28 '17 at 20:29
  • In the mailto link there is a body parameter which you can append text you want to see on body. "mailto:xyz@abc.com?cc=abc@abc.com&subject=test&body=test". – Venkat Konjeti Mar 29 '17 at 2:11
  • Sorry Venkat but I don't think you are understanding what I need. In my script the "printpage" function produces a webpage that contains data. I need that same data added to the body of the email. – TOE_CHEESE Mar 29 '17 at 18:47
  • I just want to understand that the email body you are referring, the outlook new mail window body. Is it right? If my assumption is right, you can`t push the HTML content to that window. – Venkat Konjeti Mar 29 '17 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.