contentEditable, CTRL-B CTRL-I and saving

Viewed 7799

I've just started using a contentEditable, and have not found much comprehensive information on it.

I noticed that in Chrome, I can make words bold/italic by pressing CTRL-B and CTRL-I.

Is this possibly going to be the intended behavior in other browsers? This, for instance, works in Chrome:

<div class="container" id="typer" onclick="this.contentEditable='true';">

http://jsfiddle.net/uk6DA/15/

I'm wondering if I can read this formatting, in order to save the user's edits? Also, can I create a Bold button and Italic button that will trigger CTRL-B and CTRL-I? Or would I need to depend on the user pressing CTRL-B and CTRL-I (which means providing them a note telling them)?

3 Answers

You can see which browsers support the contentEditable feature here:

https://caniuse.com/#search=contenteditable

And as Tim Down said, you can call the document.execCommand() to bold or italicize things.

However, the keyboard shortcuts cannot be expected to be the same in all browsers, browser shortcuts are not standardized. CTRL-B for example is the bookmark shortcut in FireFox.

Related