I've been calling execCommand
on the document to make the selected text bold or to set its color. But recently I need to use execCommand
on a certain range and not the selected text.
Can I do this and if so how?
execCommand() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.
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.
You can, but it needs to be the selection. So in other words, do the following:
Range
execCommand
You can create a selection
from ranges (non-IE browsers) with the following:
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
With IE, you can directly execute execCommand
on TextRange
objects, so this whole process won't be necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With