Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 …
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

772 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

10 Experts available now in Live!

Get 1:1 Help Now