2013-10-06 127 views
14

我想在我的项目中只获取TinyMce中body元素的内容,然后将该部分注入到另一个页面中。 当我提交我的textarea到我的控制器tinymce确实有内容,和html标记。删除TinyMCE中的html,head,body标签

如何摆脱它们? TinyMce内部是否有内置的功能?

这里是我的代码:

<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> 

,并在我的html页面:

<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> 
+0

我通过移除全页插件解决了这个问题:) – Mehdi

回答

33
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" 
    ], 

从脚本

+1

我的客户抱怨它,我没有在这里看到的全页插件。这就是我使用的所有内容:插件:“表格,内联poppop”。任何提示? –

+0

@PauloPedroso如果你看到插件:[...]部分,通过删除整个页面,你将能够得到它。 – Mehdi

+0

谢谢Mehdi,如果我记得,有一些控件,你说你想添加新行,并将其设置为false,我可以完成这些工作。不幸的是,该项目已与另一家公司在一起,我无法访问代码来了解我如何管理它。但我确实记得它的部分没有fullpage插件。 –

0

这里卸下全页插件是获取正文内容的解决方案和字符数

JS FIDDLE DEMO

tinymce.init({ 
    selector: "textarea", 
    toolbar: "mybutton", 
    setup: function(editor) { 
     editor.addButton('mybutton', { 
      icon: 'image', 
      onclick: function(e) { 
       console.log(e.target); 
       console.log(editor.getContent()); 
       var utf8length = 0; 
       var string = editor.getContent(); 
       for (var n = 0; n < string.length; n++) { 
     var c = string.charCodeAt(n); 
     if (c < 128) { 
      utf8length++; 
     } 
     else if((c > 127) && (c < 2048)) { 
      utf8length = utf8length+2; 
     } 
     else { 
      utf8length = utf8length+3; 
     } 
    } 
    console.log(utf8length); 
    var str = editor.getContent(); 
     var m = encodeURIComponent(str).match(/%[89ABab]/g); 
    console.log(editor.getContent()); 
    console.log(str.length + (m ? m.length : 0)); 


        } 
     }); 
    }}); 
0

这可能是简单的:

b = "<body>"; 
be = "</body>"; 
t = tinyMCE.activeEditor.getContent(); 
t = t.substr((t.indexOf(b) + b.length), (t.indexOf(be)-1)) 

的 “T” 值可以再积极地放在TinyMCE的编辑器的 “文本域” 值(未setContent()),发送前。

希望帮助..