Javascript iframe don'的Execcommand;行不通

Javascript iframe don'的Execcommand;行不通,javascript,designmode,Javascript,Designmode,我正在制作自己的所见即所得编辑器。但是我不能用execcommand函数将任何文本加粗。我正在使用下一个代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; char

我正在制作自己的所见即所得编辑器。但是我不能用execcommand函数将任何文本加粗。我正在使用下一个代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Untitled Document</title>
        <script type="text/javascript">
            function loadWysiwyg() {
                if(window.navigator.appName == "Microsoft Internet Explorer") {
                    reactioneditor.document.designMode = "on"; 
                } else {
                    document.getElementById('reactioneditor').contentDocument.designMode = "on"; 
                }
            }
            function make_bold() {
                document.getElementById("reactioneditor").contentWindow.document.execCommand("bold", false, null); 
            }
        </script>
    </head>

    <body onload="loadWysiwyg();">
        <iframe id="reactioneditor" style="border: 1px solid #CCC;width: 100%; height: 200px;"></iframe>
        <button id="makebold" onclick="make_bold();">Maak bold</button>
    </body>
</html>

无标题文件
函数loadWysiwyg(){
如果(window.navigator.appName==“Microsoft Internet Explorer”){
reactioneditor.document.designMode=“on”;
}否则{
document.getElementById('reactioneditor').contentDocument.designMode=“on”;
}
}
函数make_bold(){
document.getElementById(“reactioneditor”).contentWindow.document.execCommand(“粗体”,false,null);
}
玛克黑体
我读了很多教程,但没有效果,我现在不知道如何修复它


有人可以吗?

你的代码在IE、Firefox和Chrome中都适用。我在iFrame中写入一些文本,选择它,然后单击按钮。这些是你正在采取的步骤吗?你有什么错误吗

天哪,我真傻。我认为execcommand适用于iframe中的整个文本(不选择它),谢谢您的帮助!没问题,我想可能就这么简单。通常,
execCommand
将对用户选择的文本执行传递给它的操作。