0

So I have the following problem.

At the moment I am outputting HTML text from a CMS, this HTML is a customized email template. Which is a simple as

<p>Hi</P>
<p>THis is your URL : http://www.yoursite.com?id=15151</p>
<p>Thanks</p>
<p>Company X</p>

And we are outputting this to the screen.

What I am looking for is a sort jquery button which is called "Copy" and it copies the text above and they can paste in email later and keeps formatting.

Musa
  • 89,286
  • 16
  • 105
  • 123
StevieB
  • 5,455
  • 35
  • 99
  • 181
  • Look at : http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript – adriendenat Oct 25 '12 at 16:35
  • Can you define "paste in email"? Is this email HTML based, rich-text based, plain text? And are you talking about placing the "formatted text" into the clipboard? – freefaller Oct 25 '12 at 16:35

1 Answers1

0

(For cross-browser copy-to-clipboard, this is possibly a duplicate question: How do I copy to the clipboard in JavaScript?)

Using this library, https://github.com/jonrohan/ZeroClipboard, (mentioned in the post above), you'd want to wrap your to-be-copied source text in something with an ID, like so:

<div class="emailText">
    <p>Hi</P>
    <p>THis is your URL : http://www.yoursite.com?id=15151</p>
    <p>Thanks</p>
    <p>Company X</p>
</div>

Then, in the Javascript call that sets the text for the library, you'd do something like:

<script language="JavaScript">
  var clip = new ZeroClipboard.Client();
  clip.setText( $(".emailText").html() );
  clip.glue( 'd_clip_button' );
</script>
Community
  • 1
  • 1
Jason M. Batchelor
  • 2,911
  • 14
  • 24