views:

887

answers:

2

I'm building a custom RTE that converts user input to a homebrewn markup, now idiot that I am I did this using an iframe with designMode = "On" and got it to work in firefox using styleWithCSS = false so that I could easily convert the <b> (yes... b :( ) into my markup which would then output the proper code instead of me having to read from <span style="... now my problem is, I cant seem to find something that looks or acts like styleWithCSS = false for IE, Chrome or Opera, any suggestions are welcome.

+4  A: 

Use this:

            try {
                Editor.execCommand("styleWithCSS", 0, false);
            } catch (e) {
                try {
                    Editor.execCommand("useCSS", 0, true);
                } catch (e) {
                    try {
                        Editor.execCommand('styleWithCSS', false, false);
                    }
                    catch (e) {
                    }
                }
            }

Before any other execCommands. Tested on ff3 ie7 ie8 safari chrome

desmati
let us know if works on any other browser
desmati
I'll give it a go later today... yeah, I dont stop by that often, sorry.
Kristoffer S Hansen
Worked just fine, thankyou
Kristoffer S Hansen
Your welcome, if this my post was your answer, please mark it and let others know that.
desmati
@desmati why do you try the styleWithCSS twice, once with 0 and once with false? Won't 0 cast to false?
thomasrutter
A: 

(This comment is directly related to desmati's response to original question. I have the same issue original poster had, and the provided solution does not seem to work for me. Please read comments before you vote them down.)

Could anyone tell me why this does not work in Chrome, please? Ctrl+B creates <b> instead of <span> with style-attribute.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>styleWithCSS in Chrome</title>

        <script type="text/javascript">
            function onLoad()
            {
                document.body.contentEditable = true;
                document.execCommand("styleWithCSS", false, true);
            }
        </script>
    </head>

    <body onload="onLoad();">
    </body>
</html>
Jaroslav Záruba
If you have a question, please ask a question. Don't "answer" someone else's question.
David Dorward
If you actually read my comment you would notice that my comment is the same issue original poster was asking about. The solution provided by desmati does not seem to work for me, it is directly related to his response. If I could post directly under his comment I would certainly do so.Thank you for voting my comment down without even reading it. :(
Jaroslav Záruba