Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rich text editor, bold text using the strong tag

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!

like image 616
lawls Avatar asked Feb 17 '13 12:02

lawls


1 Answers

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:

  1. Write your own code to do the bold styling. Unfortunately it is non-trivial to do this properly. You could look at how major WYSIWYG editors such as CKEditor and TinyMCE do it.
  2. Run some code to convert <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.
like image 63
Tim Down Avatar answered Oct 18 '22 12:10

Tim Down