Search code examples
javascriptdojowidgetdijit.formibm-content-navigator

How to get the whole HTML value from Dijit Editor


Hello Experts I need help

I'm using dojo Dijit Editor "rich text editor" field in my widget, on page load I fetch HTML text from database and I set the rich text editor with the HTML normally, Then user can edit the displayed text and on page close I have to set the field in database with the source HTML of the edited text by user the problem is when I do the following "myDB_txt=myEditor.getValue();" getValue() doesn't return the complete HTML code it removes HTML tag and header tag and body tag which causes me troubles.


Solution

  • Simply use myEditorWidget.get("Value") where myEditorWidget refer to your dijit/Editor indtance

    To wrap this result you can define a function that return result wraped by html tags

    wrapResult(myEditor.get("value")));
    
    function wrapResult(html) {
    
      return "<html> <head></head> <body>"+html+"</body></html>";
    
    }
    

    Here is a Sample with wraped result Fiddle .

    Otherwise If you want to get the whole HTML enclosing the content dijit ,

    you will get access to it's Iframe ( that has the id="editor_iframe") and then get get the html document of this last like bellow (here you should import dojo/query package)

    query("#editor_iframe")[0].contentDocument.documentElement.outerHTML
    

    Here is another Fiddle .