RichTextEditor exposes the following methods.

Method Description
editor.GetText() This method is used for retrieving the content of RichTextEditor as HTML.

Example:

function RichTextEditor_OnTextChanged(editor)
{
	document.getElementById("textarea1").value=editor.GetText();
}
 
editor.SetText() This method is used for setting the content of RichTextEditor.

Example:

function RichTextEditor_OnLoad(editor)
{
	editor.SetText("Hello World");
}
 
editor.InsertHTML(html) This method is used for inserting the specified HTML into a range within an editor document. If anything is selected, the selection is replaced with the new HTML and text.

Example:

var editor;
function RichTextEditor_OnLoad(rteeditor) {
	editor = rteeditor;
}
function myinserthtml
{
    if(editor)editor.InsertHTML("Hello World");
}
 
editor.InsertText(text,bstart) This method is used for inserting the specified plain text into a range within an editor document then move cursor to the begin/end of the added content.

Example:

var editor;
function RichTextEditor_OnLoad(rteeditor) {
	editor = rteeditor;
}
function myinserttext
{
    if(editor)
    {
        editor.InsertText("Start - Hello World",true);
        editor.InsertText("End - Hello World",false);
    }
}
 
editor.PasteHTML(html) Same as editor.InsertHTML(html).
editor.AppendHTML(html) Moves the cursor to the end of the editor document, then inserts HTML.

Example:

var editor;
function RichTextEditor_OnLoad(rteeditor) {
	editor = rteeditor;
}
function myappendhtml
{
    if(editor)editor.AppendHTML("Hello World");
}
 
editor.InsertNode(node) Inserts the specified node at the start of the current Range.
editor.IsTabEdit() Returns a Boolean value that indicates whether the current mode is the Design mode.
editor.IsTabCode() Returns a Boolean value that indicates whether the current mode is the Source mode.
editor.IsTabView() Returns a Boolean value that indicates whether the current mode is the Preview mode.
editor.GetConfig() This method is used for retrieving the configuration of RichTextEditor. The details of configuration(RTE_Configuration) can be found configuration file file (richtexteditor\scripts\config.js).

Example:

function RichTextEditor_OnLoad(rteeditor) {
	var config = rteeditor.GetConfig();
	alert(config.skin);
}
 
editor.ExecUICommand(element,command,arg0) Executes a layout related command on the current selection, or the given range.

Example:

var editor;
function RichTextEditor_OnLoad(rteeditor) {
	editor = rteeditor;
}
function showrtetable
{
    if(editor)editor.ExecUICommand(this,'InsertTable','');
}
function showrtestyledropdown
{
    if(editor)editor.ExecUICommand(this,'ShowXmlFloatbox','setstyles.xml');}
}
 
editor.ExecCommand(command,arg0) Executes a command on the current selection, or the given range.

Example:

function RichTextEditor_OnTextChanged(rteeditor)
	rteeditor.ExecCommand("forecolor","red");
	rteeditor.ExecCommand("bold");
	rteeditor.ExecCommand("undo");
}
 
editor.IsCommandReady(command) Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document.

Example:

function RichTextEditor_OnTextChanged(rteeditor)
	var canundo=rteeditor.IsCommandReady("undo");
}
 
editor.IsCommandActive(command,arg0) Returns a Boolean value that indicates the current state of the command.

Example:

function RichTextEditor_OnTextChanged(rteeditor)
	var isbold=rteeditor.IsCommandActive("bold");
}
 
editor.GetLangText(name,nullifnotfound) Extracts a localized string by the specified name. The language files are located in richtexteditor\lang folder. They consist of a group of name-value pairs.

Parameters:

name -- the name of a name-value pair.
nullifnotfound -- the value of a name-value pair. Return null if not found.

editor.GetWindow() Gets the active editor window.

Example:

function RichTextEditor_OnTextChanged(rteeditor)
	var editwin = rteeditor.GetWindow();
}
 
editor.IsDirty() Determines whether the content has changed.

Example:

function RichTextEditor_OnLoad(rteeditor)
	alert(rteeditor.IsDirty());
}
 
editor.IsFocused() Determines whether this element has logical focus.

Example:

function RichTextEditor_OnLoad(rteeditor)
	alert(rteeditor.IsFocused());
}
 
editor.Focus() Attempt to set the focus of the editor content window.

Example:

function RichTextEditor_OnLoad(rteeditor)
	rteeditor.Focus();
}
 
editor.GetSelectionType() Determines the selection type. This could be "Point","Range","Control" or "None".

Example:

function RichTextEditor_OnTextChanged(rteeditor)
	alert(editor.GetSelectionType());
}
 
editor.SaveBookmark() Creates a bookmark on the current range.
editor.RestoreBookmark(bookmark) Restores to a bookmark.
editor.MoveToDocumentBegin() Moves cursor to first character of the document.
editor.MoveToDocumentEnd() Moves cursor to the end of the document.
editor.FindNextText() Finds the position of the next text.
editor.GetPointNode() Gets the node object of the current selection.
editor.GetPointOffset() Gets the point offset.
editor.GetRangeNode() Gets the ending node of the range.
editor.GetRangeOffset() Gets the offset of the range's ending node.
editor.SelectControl(node) Selects the node.
editor.SelectContent(node) Selects the content of the node.

Send feedback about this topic to CuteSoft. © 2003 - 2014 CuteSoft Components Inc. All rights reserved.