I want to format selected text to a heading, the way I am doing it works fine in Firefox and Google Chrome but it doesn't 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?
The problem seems to be one of syntax. IE expects the tag to be formatted while the other browsers don't.
See here :
In Internet Explorer, the name of the element must be placed between tag delimiters (such as
<H1>
). Firefox, Opera, Google Chrome and Safari support all block elements, Internet Explorer supports only the h1 - h6, address and pre elements
Internet Explorer仅支持标题标记H1
- H6
, ADDRESS
和PRE
,它们还必须包含标记分隔符<
和>
,例如<H1>
。
works perfect for me in IE9
your codes probably wrong, mines more like:
var contentWindow = editor.contentWindow;
contentWindow.focus();
contentWindow.document.execCommand('formatBlock', false, '<h1>');
contentWindow.focus();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.