本文介绍了execCommand()现在已过时,还有什么选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算结合使用Document.execCommand()方法和contenteditable属性来构建我的自定义WYSIWYG编辑器.但是,当我在文档中找到Document.execCommand()时,我发现它已经过时了.什么是现代的(或现存的)替代方案?

I intended to use Document.execCommand() method along with contenteditable attribute to build my custom WYSIWYG editor. But when I checked the documentation for Document.execCommand(), I found that it's now obsolete. What's the modern (or extant) alternative for it?

推荐答案

我创建了Rich编辑器,用于平台的XML(HTML5 + XHTML)编辑.我不会说document.execCommand()已完全失效,因为它的某些部分仍然可以正常工作.不幸的是,对我来说主要的问题是浏览器使用许多不同的代码来生成那些盲人或接近盲人使用的屏幕阅读器无法识别的样式.

I created the Rich Editor for my platform's XML (HTML5 + XHTML) editing purposes. I would not say that document.execCommand() is completely dead because some parts of it still work fine. Unfortunately the primary issue for me was that browsers use a lot of different code to generate those styles which are not recognized by screen readers used by those who are blind or nearly so.

我不得不克服的最昂贵的时间错误是壁虎/普雷斯托错误,在视觉和技术上的选择(为什么它们不是同一个东西,不要问我)会导致DOM的一部分更改了用户不想要的内容,这可归结为以下事实:每个字符的像素数很低,因此,如果Rich Editor不遵守视觉选择,用户将很快走开.这需要四个月来征服,而且还有其他错误.

Additionally the most expensive time bug I ever had to conquer was a Gecko/Presto bug where the visual and technical selections (why they aren't the same thing, don't ask me) would result in part of the DOM being changed that the user did not intend and this would come down to the fact that the pixel count per character is low so if the Rich Editor did not honor visual selections a user would very quickly walk away. That required four months to conquer and there are other bugs too.

尽管要像我一样构建HTML/XML编辑器,但最终还是很艰难的,尽管您打算不仅测试得好,而且测试到讨厌的程度,还应该计划至少六个月然后只有一个人出现并指出另一个错误.

Ultimately it's a harsh though achievable endeavor though if you intend to build an HTML/XML editor like I did you should plan for at least six months if you plan to not only do it properly though test it to the point of hating cake to then only have someone come along and point out yet another bug.

您的主要重点JavaScript应当放在以下方面:

Your primary focus JavaScript wise should be on the following:

  • document.createRange()
  • window.getSelection()
  • appendChild
  • insertBefore
  • insertBefore + nextSibling
  • replaceChild
  • document.createRange()
  • window.getSelection()
  • appendChild
  • insertBefore
  • insertBefore + nextSibling
  • replaceChild

我实际上一直打算修改我的Rich Editor(尽管没有正确重写,但已经得到了补丁),但是欢迎您在源代码加载到我的个人资料所链接的网站的博客页面中时查看源代码.最初的项目花了我11个月的时间,但是根据我现在的经验,我认为这将花费我大约三到四个时间.如果您是认真的人,我强烈建议您远离框架和库. 但是……但是,它们使生活更轻松!" ...,直到您要使用新版本并不得不重写整个项目为止.第一次使用纯JavaScript并取消毫无意义的维护.祝你好运!

I actually have been intending to revise my Rich Editor (it's been getting patched though not yet properly rewritten) though you're welcomed to look at the source code when it loads on a blog page in the site linked in my profile. The original project took me 11 months though with my experience now I think it would take me about three to four. If you're serious I highly recommend staying the hell away from frameworks and libraries. "But ... but, they make life easier!" ... until you want to use a new version and have to rewrite the entire project. Use pure JavaScript the first time and negate pointless maintenance. Good luck!

这篇关于execCommand()现在已过时,还有什么选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 11:48