Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The easiest way is the following. It's used by <a href="http://tinymce.moxiecode.com/" rel="noreferrer">TinyMCE</a> and <a href="http://ckeditor.com/" rel="noreferrer">CKEditor</a> and many others. There are many variations: in particular, if you are creating a code editor, there are clever tricks you can do using textareas and a monospaced font.</p> <ul> <li>Dynamically create an iframe and place the editable content within that iframe's document</li> <li>Set the iframe to be editable either by setting its document's <code>designMode</code> property to "on" or by setting its <code>&lt;body&gt;</code> element's <code>contentEditable</code> property to true. Note that <code>designMode</code> support predates <code>contenteditable</code> in Firefox and as a consequence is a lot less buggy.</li> <li>Add buttons (such as bold, italic, insert image, etc) somewhere sensible (such as directly above the editable iframe) in the main document that act on the selected content within the iframe. All browsers supply an <code>execCommand()</code> method (see <a href="http://msdn.microsoft.com/en-us/library/ms536419%28v=vs.85%29.aspx" rel="noreferrer">MSDN</a> and <a href="https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing_Commands" rel="noreferrer">MDN</a>, for example) for doing many of these actions, although there is some variation in exactly how they work and what mark-up they produce.</li> </ul> <p>That's the very basics of how it works. There are tons of other, complicated things that most editors do that aren't immediately obvious, in part to iron out the many differences between browsers and in part to provide extra functionality not covered by the built-in browser commands. It's a very complicated and difficult thing to get right, requires a high degree of expertise and commitment and is not something to be taken on lightly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload