Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing html, head, body tag inside TinyMCE

I want to get only the content of the body element in TinyMce in my project and then inject that part inside another page. when I submit my textarea to my controller the content of tinymce does have , and html tag.

how to get rid of them ? is there any built in functionality inside TinyMce for doing this ?

Here is my code:

    <script type="text/javascript">         /*tinymce definition*/         tinymce.init({             selector: "textarea.tinymce",             theme: "modern",             height: 10,             plugins: [                  "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker example fullpage",                  "searchreplace visualblocks visualchars code fullscreen insertdatetime media nonbreaking",                  "save table contextmenu directionality emoticons template paste textcolor wordcount"            ],            content_css: "css/content.css",            toolbar: "insertfile undo redo | styleselect | save | table | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons charmap code | hr paste pagebreak searchreplace spellchecker template visualblocks insertdatetime",             style_formats: [                 {title: 'Bold text', inline: 'b'},                 {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},                 {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},                 {title: 'Example 1', inline: 'span', classes: 'example1'},                 {title: 'Example 2', inline: 'span', classes: 'example2'},                 {title: 'Table styles'},                 {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}             ]          });     </script> 

and in my html page :

    <div class="page-content">         <form action="somewhere" method="post" role="form">             Title:<br/> <input type="text" name="title" style="width:100%"/><br/> <br /> Your Text:<br/>             <textarea name="content" class="tinymce" cols="30" rows="10" ></textarea>             <br /> <br /> <input type="submit" name="submit" />         </form>     </div> 
like image 832
Mehdi Avatar asked Oct 06 '13 13:10

Mehdi


People also ask

How do you get content in TinyMCE with HTML tags?

The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do you get rid of Tinyed by power on TinyMCE?

Use the branding option to disable the “Powered by Tiny” link displayed in the status bar for product attribution. Important: Product attribution is required for free and open source users. For information on TinyMCE attribution requirements, see: Logo & attribution requirements.

Can we skip head in HTML?

Yes , You are free to omit head and body tags from your html code. There is no cons of omitting html , head , body tags since they are optional as per w3c.


2 Answers

    plugins: [         "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",         "save table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker"     ], 

remove the fullpage plugin from script

like image 74
Mehdi Avatar answered Sep 23 '22 19:09

Mehdi


This might be simpler:

b = "<body>"; be = "</body>"; t = tinyMCE.activeEditor.getContent(); t = t.substring((t.indexOf(b) + b.length), (t.indexOf(be)-1)) //need substring() (including comment b/c can't make edit under 6 chars) 

The "t" value can be then actively placed in the "textarea" value (not setContent()) of the tinymce editor, before sending.

Hope that helps..

like image 23
user6565001 Avatar answered Sep 19 '22 19:09

user6565001