Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.execCommand('heading' ..') in Chrome

I'm trying to use the rich-text editing command functions as described in MDN here

The API for this seems fairly simple. Select some text, and execute the command, and it'll wrap the content with it. Cool stuff!

In Firefox (Aurora), this works great:

document.execCommand('heading', false, 'H1');

However the same command in Chrome returns nothing. Is this not implemented the same way (or at all) in Chrome?

Thanks!

like image 704
Bartek Avatar asked Jan 11 '23 15:01

Bartek


1 Answers

I am afraid Chrome does not support the heading command yet. You can check this page in Chrome for available commands: http://tifftiff.de/contenteditable/compliance_test.html

What you are looking for is the formatBlock command used like so:

document.execCommand('formatBlock', false, '<h1>');
like image 86
Ben Avatar answered Jan 18 '23 07:01

Ben