Rich Text Editor in javascript

Posted by chanthou on Stack Overflow See other posts from Stack Overflow or by chanthou
Published on 2010-03-12T03:24:35Z Indexed on 2010/03/12 3:27 UTC
Read the original article Hit count: 605

Filed under:
|
|
|

iframe .text-bold{ border:1px solid orange; background-color:#ccc; width:16px; height:16px; font-weight:bold; cursor:pointer; } .active{ border-color:#9DAECD #E8F1FF #E8F1FF #9DAECD; background-color:yellow; } function init( ) { iframe = document.createElement("iframe"); document.body.appendChild(iframe); iframe.onload = setIframeEditable;

            isBold=false;
            div=document.getElementById("bold");
        }
        var setIframeEditable = function(){
            iframe.contentDocument.designMode='on';
            iframe.focus();
        }

        function makeBold(){
            if(!isBold){
                //console.log(iframe.contentDocument.execCommand("bold", false, null));
                iframe.contentDocument.execCommand("bold", false, null);
                div.className += " active";
                isBold=true;
                iframe.focus();
            }else{
                //console.log(iframe.contentDocument.execCommand("bold", true, null));
                iframe.contentDocument.execCommand("bold", false, null);
                div.className ="text-bold";
                isBold=false
                iframe.focus();
            }


        }
    </script>
</head>
<body onload="init()">
    <div id="bold" class="text-bold" onclick="makeBold()">B</div>
</body>

© Stack Overflow or respective owner

Related posts about rich

Related posts about text