Execcommand formats headers in IE

I want to format the selected text in the header, as I do it, it works fine in Firefox and Google Chrome, but it does not work in IE9, here is how I do it:

document.execCommand('formatBlock',false,'h1');

Does anyone know how to achieve the same task in Internet Explorer 9?

+3
source share
3 answers

The problem seems to be syntactic. IE expects the tag to be formatted and other browsers will not.

Look here :

In Internet Explorer, the element name must be placed between tags (for example, <H1>). Firefox, Opera, Google Chrome and Safari support all block elements, Internet Explorer supports only h1 - h6, address and preliminary elements

+4

Internet Explorer H1 - H6, ADDRESS PRE, < >, , <H1>.

+1

works great for me in IE9

your codes are probably wrong, the mines are more like:

        var contentWindow = editor.contentWindow;
        contentWindow.focus();
        contentWindow.document.execCommand('formatBlock', false, '<h1>');
        contentWindow.focus();
0
source

All Articles