What is the alternative to the obsolete method (according to MDN) Document.execCommand?

Asked

Viewed 80 times

0

I’m trying to make a simple text editor with javascript and need a way to format a text within a div who is serving as a textArea.

I looked up some ways on the Internet and they all use the method document.execCommand, but according to the MDN this method is obsolete:

Mensagem da MDN sobre execCommand estar obsoleto

Is there any alternative method that I can do the same process of formatting the text within the div?

  • The strange thing is that only on this page of the MDN it says this, the others that speak of the same command as https://developer.mozilla.org/en-US/docs/Add-ons/WebExtensions/Interact_with_the_clipboard, although the main one was edited in January 2020, but I can’t be sure if this was confusion of who edited (the MDN is Community), on the site W3.org (https://www.w3.org/TR/clipboard-apis/) and others don’t talk about the disuse and removal of this method, it seems to me confusing, but I can’t say, after all, humans edit, something always lags behind.

  • Note: I used the command and no browser issued Warning/Warnings when I used the command, not even Firefox. Usually when a function, method, way of use or syntax or API are in disuse the browsers inform, of course this is something that already has a time and has already been adjusted in the browser to issue. Recalling that MDN is also responsible for Firefox

  • Yeah, well, I thought it was pretty weird, too, but I kind of got a kick back when it came to using and eventually it stopped working...

  • And it’s hard because I can’t find anything that can fulfill the functionalities of the method

  • Therefore, I’m thinking that some writer made a mistake at MDN, the issues being community even worse, of course it helps, but back and forth a shave. It can be done without, but the only way I see is to manipulate the DOM with activeElement+selectRange and to customize manually (what would work, but it is very laborious).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.