Getting selected html content in tinymce editor

前端 未结 2 1900
梦毁少年i
梦毁少年i 2020-12-31 07:57

I have created a custom button using this code

    setup : function(ed) {
    ed.addButton(\'Tittle\', {
                title : \'Tittle\',
                         


        
相关标签:
2条回答
  • 2020-12-31 08:07
    var node = tinyMCE.activeEditor.selection.getContent();
    tinyMCE.execCommand('mceReplaceContent', false, %your value, can use node%");
    
    0 讨论(0)
  • 2020-12-31 08:28

    try

    selection.getContent({format : 'text'});
    

    or

    selection.getContent({format : 'html'});
    

    http://www.tinymce.com/wiki.php/API3:method.tinymce.dom.Selection.getContent

    EDIT: To achieve what you want you could do:

    if(c!="TITTLE") {
    
      node = ed.selection.getNode();
    
      with(document.getElementById(iframe_id).contentWindow){
          var newElement = document.createElement("tittle");
          newElement.innerHTML = node.innerHTML;
      }
    
      node.parentNode.replaceChild(newElement, node);
    
    }
    else {
    
      node = ed.selection.getNode();
    
      with(document.getElementById(iframe_id).contentWindow){
          var newElement = document.createTextNode(node.innerHTML);
      }
    
      node.parentNode.replaceChild(newElement, node);
    }
    
    0 讨论(0)
提交回复
热议问题