← Toda la documentación

Establecer y obtener el contenido HTML

Esta guía explica las formas habituales de establecer y obtener el contenido HTML en RichTextEditor.

1. Obtener el contenido con JavaScript

<!-- Create a new DIV element with all of the content that we want inside the Editor -->
<div id="div_editor1"></div>
  //Initialize Richtexteditor for the matched element
  var editor1 = new RichTextEditor("#div_editor1");
  //Setting Content with Javascript
  editor1.setHTMLCode("Use inline HTML or setHTMLCode to set the default content.");
<!--  Retrieve the HTML from the editor by using the editor.getHTMLCode() method. -->
<button onclick="alert(editor1.getHTMLCode())">Show Html Code</button>

2. Obtener el contenido automáticamente con un POST de <form> HTML

Cuando RichTextEditor sustituye un elemento <textarea> dentro de un <form>, imita el comportamiento del <textarea> original al enviar el formulario. Es decir, el contenido del editor se envía junto con los demás elementos del formulario, usando como clave el atributo name del <textarea> original.

<!-- Create a new DIV element with all of the content that we want inside the Editor -->
<textarea id="inp_editor1">&lt;p&gt;Initial Document Content&lt;/p&gt;</textarea>
//Initialize Richtexteditor for the matched element
var editor1 = new RichTextEditor("#inp_editor1");