Image is not displayed in IE Browser Using Editor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • venkateshkumar
    New Member
    • Apr 2008
    • 1

    Image is not displayed in IE Browser Using Editor

    I have used rich text editor for Content management system.In this editor, have a InsertImage icon.We click that, select images from galley and insert the image.In firefox, it's simply placed in Editor. But IE it's placed in top of the page.


    Used code:

    function rteInsertHTML(h tml) { if (document.all) { var oRng = document.getEle mentById(rteNam e).contentWindo w.document.sele ction.createRan ge(); oRng.pasteHTML( html); oRng.collapse(f alse); oRng.select();} else { document.getEle mentById(rteNam e).contentWindo w.document.exec Command('insert HTML', false, html);}
    }


    In IE it's come in if loop, In fierfox, it's come in else condition(so image displayed).
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Please use code tags when posting code so that it can actually be read.

    Code:
        function rteInsertHTML(html) { 
            if (document.all) { 
                var oRng = document.getElementById(rteName).contentWindow.document.selection.createRange();      
                oRng.pasteHTML(html); 
                oRng.collapse(false); 
                oRng.select();
            } else {        document.getElementById(rteName).contentWindow.document.execCommand('insertHTML', false, html);
            }
        }
    See that is much easier to read...... although it could still be better.

    Ok first RTF (Rich Text Format) editors do not create HTML so if you are intending to use this in a browser it is not likely to work.

    Secondly there is intentional logic here to treat IE and FF differntly. So your problem is likely inside the "if (document.all)" test. That is the section that is specific to IE.

    Third did you create the JavaScript in this file? It looks incomplete. There are references to variables like "rteName" that are not defined.

    Fourth it is extremely unlikely that what ever element is being referenced by the value in "rteName" has a collapse() or select() function.

    Fith is even less likely that the element being referenced by the value in "rteName" has contentWindow.d ocument.selecti on child elements. Or that the contentWindow.d ocument.selecti on child elements have a createRange() function.

    Comment

    Working...