【问题标题】:Execcommand for iframe don't workiframe 的执行命令不起作用
【发布时间】:2010-03-02 18:59:20
【问题描述】:

我正在制作自己的所见即所得编辑器。但是我不能使用 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>

我阅读了多个教程,但没有效果,我现在不知道如何修复它。

有人可以吗?

【问题讨论】:

    标签: javascript designmode


    【解决方案1】:

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

    【讨论】:

    • 天哪,我太傻了。我虽然 execcommand 适用于 iframe 中的整个文本(没有选择它)谢谢你帮助我!
    • 没问题,我想可能就是这么简单。通常execCommand 将在用户选择的文本上执行传递给它的操作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多