Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentEditable Alternative

I've been looking into creating a Rich Text editor, and at first I was planning on using contentEditable, but it turns out the results are extremely inconsistent and that the output HTML is often broken.

I was wondering if there are any alternatives to using contentEditable, such as the way Google Docs does it (they created there own engine).

like image 459
skimberk1 Avatar asked Aug 07 '26 09:08

skimberk1


2 Answers

Even Google Docs are built on contentEditable. They, however, use it in a different way most editors out there do.

When you focus the document area, it just seems like it is focused because of the fake caret. The actual focus goes to an <iframe> with keyboard event listeners set up. The engine (kix) then modifies the document area based on the keys you press.

This is awesome because there are really no serious cross-browser inconsistencies as the browser is not the one modifying the DOM.

The only alternative I can think of might be a simple text input instead of a contentEditable element but why bother with issues like max length when you can just take advantage of contentEditable ;-)

like image 95
J. K. Avatar answered Aug 09 '26 23:08

J. K.


Why not give TinyMCE a go? It is quite good and fairly refined - just need to combine it with PHP and you can save the contents :)

like image 40
MrJ Avatar answered Aug 09 '26 21:08

MrJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!