Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by LR on Jan 20, 2009 23:44
open dhtmlx forum
get Editor Content without HTML

Hi,

Is there any way to get the text content inside the text area of Editor without html...? Currently the getContent() function gives you the text with the formatting.For a particular section of my work,I need the unformatted text content.
Thanks in advance !
Answer posted by Support on Jan 21, 2009 04:56

Editor API doesn't allow to get text conent. You can try to use JavaScript methods to replace all html tags with white spaces. For example:

var html = editor.getContent();

var text = html.replace(/<[^>]*>/g,' ').replace(/  +/g,' ');

Answer posted by Nick Armtage on Jan 27, 2009 05:14
I had a similar issue where I only wanted the text so I modified my local version of dhtmlxEditor.js and added the getContentText method (for IE you can use .innerText property directly).
Not sure if this is the correct (or "official") way, but it worked for what I needed.

    /**
    * @desc: gets html text content of editor document
    * @type: public
    * @topic: 1
    */
    this.getContentText = function(){
        if(!this.edDoc.body)
            return "";
        else{
            if (_isIE)
            {
                return this.edDoc.body.innerText;
            }
            return this.edDoc.body.innerHTML.replace(/<[^>]*>/g,' ').replace(/  +/g,' ');
        }
    }
Answer posted by Support on Jan 27, 2009 05:59
Thank you for the provided method. Possibly we will add the similar method to the next editor realese.