views:

14

answers:

1

Hello everybody,

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"&gt;
<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>

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

Is there anyone who can?

+1  A: 

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?

rosscj2533
omg, i am so stupid. i though that the execcommand works for the whole text in the iframe(withouth selecting it) thank you for helping me!
Tom
No problem, I thought it might be something that simple. Generally the `execCommand` will perform the action passed to it on the user's selected text.
rosscj2533