开发者

Execcommand for iframe don't work

I am making my own WYSIWYG editor. But i can't make any text bold with the execcommand function. I am using the next code:

<!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"; 
                }
            }
            funct开发者_如何学Goion 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>

I readed multiple tutorials but with no effect, i don't now how i can fix it.

Is there anyone who can?


Your exact code works for me in IE, Firefox, and Chrome. I wrote some text into the iFrame, selected it, and clicked the button. Are those the steps you are taking? Are you getting any errors?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜