Is there something better than document.execCommand?

前端 未结 2 739
不知归路
不知归路 2020-12-31 01:23

When implementing a web-based rich-text editor, I read that document.execCommand is useful for performing operations on an HTML document (like making a selectio

相关标签:
2条回答
  • 2020-12-31 01:47

    There is one alternative to using execCommand - implementing the whole interaction of an editor including blinking of a cursor. And it has been done. Google does it in docs, but there's something free and open-source too. Cloud9 IDE http://c9.io has an implementation. AFAIK, github uses that editor for some time now. And you surely can do anything under that, because there's no native code involved - like in execCommand

    The repo is here: https://github.com/ajaxorg/cloud9 (it contains the whole IDE, you will need to find the code for the editor. )

    Also - dom mutation events are deprecated. If you can drop support for old browsers, try mutation observer. If not - try to avoid detecting DOM changes at all and intercept changes in the editor's implementation. It might be the way to go for the new browsers too.

    0 讨论(0)
  • 2020-12-31 01:52

    There is Trix rich text editor, from their description it looks like avoiding inconsistent execCommand is the whole point of the project.

    0 讨论(0)
提交回复
热议问题