The Unsung Heros of Rich Text Editors II

HTML Javascript Rich Text Editor 2

In my last post I talked about how to make a document or element editable and mentioned about Document.execCommand. Now, I am going to continue the conversation.

The document.execCommand ( allows you to have the browser apply specific commands to the document that is marked as document.designMode = “on”; and it is also very important to note that many, if not most commands, need to be tested against the browser prior to be used.

Now, if you are looking to handle Rich Text Editing (RTE) within a DIV element, then this actually doesn’t change a bit (I was actually surprised by this… the browser assumes that the insertion point is all that is needed to handle the commands and will process through it appropriately… if you look at the difference (I highlighted only the difference between this and the previous code for the next code section), the only difference is what is editable.

Anyway, this does open up a whole list of doors for me, with just a quick look at the User Agent string, and then determining which commands are available and which are not, it becomes very easy to make my own RTE editor, both as an mobile and desktop version. At some point, I am probably going to build out a full setup and walk you through that, but for now, Monty Shokeen made a simple walk through last year called Create a WYSIWYG Editor With the contentEditable Attribute, and I did like how well he designed it. The only thing I might do differently is parse through the User Agent and give more/less commands based upon what the end user is showing.

Until next time, Happy Coding and may you be blessed!