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:[email protected]"
         + "[email protected]"
         + "&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>
1
  • 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 Commented Mar 29, 2017 at 10:13

1 Answer 1

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.

4
  • 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.
    – user62801
    Commented Mar 28, 2017 at 20:29
  • In the mailto link there is a body parameter which you can append text you want to see on body. "mailto:[email protected][email protected]&subject=test&body=test". Commented Mar 29, 2017 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.
    – user62801
    Commented Mar 29, 2017 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. Commented Mar 29, 2017 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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