javascript Rich Text Editors

江枫思渺然 提交于 2019-11-28 03:16:10

After more research I found the following. The functionality for building a rich-text-editor is already implemented at the browser. IE was the first to create such an API and Firefox replicated it.

Overview

The main point is that the javascript object "document" has a property called designMode which can be set to "on". This converts all the page to to a textarea-like component. Imagine that the browser opens the page the same way that MS-Word would: the user can see the formatting but he can also type in the page (normally the browser opens a page as readonly).

window.document.designMode = "On";

Because the above affects all the web page, most editors use iFrames so that the editable area is only the iFrame which has it's own document object.

On top of that, there is an API that allows easy javascript access to styling. This is exposed throw the execCommand() method. For example you can call from Javascript

document.execCommand('bold', false, '');

and the selected text will become bold.

Tutorials

I have found the following:

A brief step by step guide.

A mozilla guide. It has the most convenient API reference I have found and also some more links.

A guide by microsoft.

Use your curiosity to motivate you to just open up the source code in your favorite editor and start exploring. Since these editors are written in JavaScript the answers are free for the looking.

I realize you are looking for something more easily digested, but reading the source code can be very rewarding.

Starting to build an editor could be as simple as taking an existing open source editor and modifying it to meet your own special needs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!