How reliable is using contenteditable on a div for a WYSIWYG editor?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 06:59:23

For most uses, my preference is still for an iframe with designMode on most browsers and a contenteditable <body> element in IE, which makes it easier to work with. The reasons:

  • Having the editable content in an iframe effectively sandboxes it and allows you to drop the editor into any page with confidence that the page's CSS and DOM events cannot affect the editable content
  • designMode is more reliable in Firefox. I've seen several bugs with contenteditable that don't exist with designMode, which is probably because contenteditable was added to Firefox relatively recently whereas designMode has existed since around 2003.

As to ACE, its textarea approach is clever and has many advantages but I suspect the approach is limited to monospaced fonts. Also, CodeMirror 2 uses a related approach but is similarly limited to monospaced fonts.

contentEditable does not work with floats in IE:

<p>
  <img style="float:left" src="foo">
  <p contentEditable="true">very long text here ...
    ... this text won't flow round the image</p>
</p>

This is because contentEditable triggers the infamous hasLayout. Other than that, everything works pretty well.

The designMode and contentEditable attributes, and the APIs that drive rich text editors, are implemented in all major browsers, including Firefox, Opera, Safari, Google Chrome, and of course Internet Explorer.

http://blog.whatwg.org/the-road-to-html-5-contenteditable

Mark Finkle wrote a nice high-level summary of designMode, and later added a post about contentEditable.

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