ContentEditable Alternative

2019-03-22 17:18发布

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).

2条回答
孤傲高冷的网名
2楼-- · 2019-03-22 17:30

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 ;-)

查看更多
混吃等死
3楼-- · 2019-03-22 17:51

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 :)

查看更多
登录 后发表回答