组件返回失败代码:0x80004005(NS_ERROR_FAILURE)[nsIDOMHTMLDocument.execCommand]

时间:2013-02-01 08:12:16

标签: inserthtml

<html>
    <head>
        <script>
            function insertHTMLCode() {
                var htmlText = '<b>HI</b>';
                try {
                    document.execCommand('insertHTML', false, htmlText);
                } catch(e) {
                    console.log(e);
                }
            }
        </script>
    </head>
    <body>
        <div>
            <ys_content contenteditable="true"><!-- ~Client References -->
                <font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font> 
            <!-- ~/Client References -->
            </ys_content>
        </div>
        <input type="button" onclick="insertHTMLCode();" value="Click">
    </body>
</html>

当我尝试将HTML内容插入FireFox中的可编辑区域时,上面的代码总是抛出错误,但它在chrome中工作正常。

我的FF版本:18.0.1

1 个答案:

答案 0 :(得分:0)

   <div contenteditable="true">
        <ys_content ><!-- ~Client References -->
            <font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font> 
        <!-- ~/Client References -->
        </ys_content>
    </div>

你的包装div应该设置为contenteditable =“true”