Solved

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

Posted on 2006-06-17
5
2,217 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now