I'm working on a very very simple rich text editor. I've read about using designMode = 'On' applied to an iframe, and then I use this to create bold text:
nameOfiframe.document.execCommand('bold',false,null);
Even though it's works, execCommand() uses b
tags instead of strong
to make bold text. I took a look at some advanced rich text editor, all of them used strong
instead of the b
tag.
Is there a simple way for me to fix this? Or are execCommand() not good to use at all?
Thanks!
Unfortunately document.execCommand()
behaviour varies between browsers. As @1UnitedPower's answer mentions, document.execCommand()
is intended for for presentational rather than semantic effect.
Two possible options are:
<b>
elements into <strong>
elements after calling document.execCommand()
. This would seem the easier option. You will need some way to preserve the selection while doing the conversion, if that's important to you.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