Solved

Email content within a <div> tag, from a webpage

Posted on 2006-06-17
5
2,225 Views
Last Modified: 2015-02-11
Hi,

I need to create a link / button that will send all content of a targeted <div> as an Email via the clients E-mail program (Outlook 2003). This link should open the users default email program and paste the div's content from the browser into the body of the message.

Same concept as using IE to send the page via Email but the problem is that the page is built with Frames and will not send the relative content only (ie: the <div>).

How do i create the function in Javascript in the <head> tag and call it from the <body> of the HTML page?

Thanks,
Dave
0
Comment
Question by:evansdavid
  • 2
5 Comments
 
LVL 6

Expert Comment

by:pD_EO
ID: 16929239
Something like this?

<html>
<head>
<title>Div content to email</title>
<script type="text/javascript">
<!--

function email_content(){
      var subject = "My email";
      var body = "";

      if(document.getElementById("divemail")){
            body = document.getElementById("divemail").innerHTML;
      }

      return "?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
}

//-->
</script>
</head>
<body>

<div id="divemail">
      Your content goes here
</div>

<a href="mailto: username@domain.com" onclick="this.href += email_content()">click</a>

</body>
</html>
0
 

Author Comment

by:evansdavid
ID: 16930771
Hey that does work but it places the literal HTML code of the <div> as the content into the body of the E-Mail.

So lets say:

----

<html>
<head>
<title>Div content to email</title>
<script type="text/javascript">
<!--

function email_content(){
     var subject = "My email";
     var body = "";

     if(document.getElementById("divemail")){
          body = document.getElementById("divemail").innerHTML;
     }

     return "?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
}

//-->
</script>
</head>
<body>

<div id="divemail"><br>
  <table width="100%" border="0">
    <tr>
      <td>Testing</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>1</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>2</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</div>

<a href="mailto: xxx@xxx.xxx" onClick="this.href += email_content()">click</a>

</body>
</html>

----

Problem is, the content of the <div id="divemail"> gets placed into the Body of the E-Mail in Literal code (plain text) as follows:

----

<table width="100%" border="0">
    <tr>
      <td>Testing</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>1</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>2</td>
    </tr>
  </table>
  <p>&nbsp;</p>

----

Thanks for the assist,

Its Almost working but how do I get it to come out correctly as a functional Web document in the body of the E-Mail?
Dave

0
 
LVL 6

Accepted Solution

by:
pD_EO earned 250 total points
ID: 16930851
Ah I see.  You could try changing this line...

return "?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);

To this...

return "?subject=" + encodeURIComponent(subject) + "&body=" + body;
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question