简体   繁体   中英

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.

You could try the following to retrieve the value from your dijit/Editor instance.

var content = myEditor.attr("value");
var openTags = '<html><head></head><body>';
var closeTags = '</body></html>';
var html = openTags + content + closeTags; // use this

or

var htmlWrapper = function(content){
    return '<html><head></head><body>' + content + '</body></html>';
}; 
var html = htmlWrapper(myEditor.attr("value"));

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM