简体   繁体   中英

firefox iframe designmode not working

i have web application where users can type on iframe(rich-text-editor) when they click a button an iframe will show up. html code when user click button for new iframe : <input name="add_button" type="button" value="New frame" onClick="javascript:add_new_frame();"/>

javascript code for creating iframe and designmode

 function add_new_frame(){
$("<iframe class=\"a\" id="a" name="a"/>").appendTo(id);
        var editor = document.getElementById ("a");
        editorDoc = editor.contentWindow.document; 
        editorDoc1 = document.getElementById ("a").contentDocument;                 
        var editorBody = editorDoc.body;

         if ('spellcheck' in editorBody) {    // Firefox
            editorBody.spellcheck = false;

        }

        if ('contentEditable' in editorBody) {
                // allow contentEditable
            editorBody.contentEditable = true;
             editorDoc1.designMode = "on";    
        }
        else {  
          if ('designMode' in editorDoc1) {

                editorDoc1.designMode = "on";                
            }            

        }   

    }

I have tested above on (chrome,opera,safari,IE) and it's working fine. However, it's not working on FF, the iframe is showing up but i cannot edit it (designmode is not working). is there any solution? sorry for bad english

You missed \\ in your iframe element to mask the "

function add_new_frame(){
$("<iframe class=\"a\" id=\"a\" name=\"a\"/>").appendTo(id);
        var editor = document.getElementById ("a");
        editorDoc = editor.contentWindow.document; 
        editorDoc1 = document.getElementById ("a").contentDocument;                 
        var editorBody = editorDoc.body;

         if ('spellcheck' in editorBody) {    // Firefox
            editorBody.spellcheck = false;

        }

        if ('contentEditable' in editorBody) {
                // allow contentEditable
            editorBody.contentEditable = true;
             editorDoc1.designMode = "on";    
        }
        else {  
          if ('designMode' in editorDoc1) {

                editorDoc1.designMode = "on";                
            }            

        }   

    }
<html>    <head>   <title>Untitled Page</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $ = jQuery;
        function frame() {
            $("<iframe class=\"a\" id=\"a\" name=\"a\"/>").appendTo(id);
            var editor = document.getElementById("a");
            editorDoc = editor.contentWindow.document;
            editorDoc1 = document.getElementById("a").contentDocument;
            var editorBody = editorDoc.body;
            if ('spellcheck' in editorBody) {    // Firefox
                editorBody.spellcheck = false;

            }
            if ('contentEditable' in editorBody) {
                // allow contentEditable
                editorBody.contentEditable = true;
                editorDoc1.designMode = "on";
            }
            else {
                if ('designMode' in editorDoc1) {

                    editorDoc1.designMode = "on";
                }

            }
        }     

    </script>
</head>
<body>
    <input name="add_button" type="button" value="New frame" onclick="frame()" />
    <p id="id">
        contents</p>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM