4

Not sure if any of you have done this or not, but wanted to put some feelers out there.

I have a TinyMce editor (in an MVC3 view) which a user can basically create an email "template" in. In addition, I have another textarea without TinyMce.

I want to be able to copy the plain text from the TinyMce to the textarea (it will be the "plain-text" version of the email). I've seen some js to strip out the code, but I'd like to take the links ( tags) and copy the URLs out as well.

Let me know if you have any questions! I greatly appreciate any help you may be able to give!

Matt Millican
  • 4,044
  • 4
  • 38
  • 55

2 Answers2

1

What you need here is to get the content first, strip out some of the contents, and then put it in your textarea. This is not that difficult:

  1. var content = tinymce.get('my_editor_id').getContent({format : 'raw', no_events : 1});
  2. Use the function strip_tags descibed here to strip out unwanted tags

// keep p,div and br tags in this example content = strip_tags( content,'<p><div><br>');

  1. document.getElementsById('my_textarea').innerHTML = content;
Community
  • 1
  • 1
Thariama
  • 50,002
  • 13
  • 138
  • 166
  • Copying the text is for the most part easy. But getting it pulled out so it's "usable" (which I realize is a relative term) is different. I also need to be able to take the value from the href of A tags and put the URL in the plain text – Matt Millican Feb 01 '12 at 20:42
  • what do you mean with "usable"? – Thariama Feb 02 '12 at 09:21
  • I did a variation of this. I'll try to post the code once I clean it up and do some more testing. Thanks! – Matt Millican Feb 03 '12 at 23:59
0

I don't suppose $("#TinyMceContainer").text() works?

SynXsiS
  • 1,860
  • 10
  • 12