Problem with PasteHTML in IE 7 and 8

  •  02-24-2010, 1:57 PM

    Problem with PasteHTML in IE 7 and 8

    Hello --
     
    I created a custom button that allows a user to select text in the editor and create a link using a custom web form.  When I create an HTML string to insert in place of selected text, the editor is wrapping the individual pieces of the string in paragraph tags.  This does not happen in Firefox 3.
     
    Web Control Code
    <CE:Editor ID="articleCopy" ConfigurationPath="/CuteSoft_Client/CuteEditor/Configuration/AutoConfigure/Wizard.config" BreakElement="P" UseStandardDialog="true" ShowPreviewMode="false" ThemeType="Office2007"Height="425px" Width="480px" OnLoad="SetEditorId" runat="server" />

    Javascript Code
    <script type="text/javascript">
        var editor = window.opener.document.getElementById('<%= EditorId %>');

        var doc = editor.GetDocument();
        var win = editor.GetWindow();
        var selectedhtml;

        if (doc.selection && doc.selection.createRange)
        {
           rng = doc.selection.createRange();
          
           if (rng.htmlText)
           {
              selectedhtml = rng.htmlText;
           }
           else if (rng.length >= 1)
           {
              selectedhtml = rng.item(0).outerHTML;
           }
        }
        else if (win.getSelection)
        {
            rng = win.getSelection();
           
            if (rng.rangeCount > 0 && window.XMLSerializer)
            {
                rng = rng.getRangeAt(0);
                selectedhtml = new XMLSerializer().serializeToString(rng.cloneContents());
            }
        }
       
        function setEditorHtml(tab)
        {
            var id;
           
            if (tab == 0)
            {
                id = document.getElementById("tabContainer_contentBrowserTab_contentBrowser_selectedItemId").value.replace(/\W+/g, '');
            }
            else
            {
                id = document.getElementById("tabContainer_mediaBrowserTab_mediaBrowser_selectedItemId").value.replace(/\W+/g, '');
            }
           
            var html = '<a href="~/link.aspx?_id=' + id + '&amp;_z=z">' + selectedhtml + '</a>';
            editor.PasteHTML(html);
            window.close();
        }
    </script>
     What I see in the editor's HTML view before invoking my custom action:
    <p>This is the first sentence.</p>
    <p>This is the second sentence.</p>
    What I see in the editor's HTML view when I select the second sentence and the above script runs in IE 7/8:
    <p>This is the first sentence.</p>
    <p><a href="~/link.aspx?_id=7B89C93AB52A4457B553A26D55C713F3&amp;_z=z"> </p>
    <p>This is the second sentence.</p>
    <p></a>&nbsp;</p>
                But, in Firefox 3:
    <p>This is the first sentence.</p>
    <p><a href="~/link.aspx?_id=7B89C93AB52A4457B553A26D55C713F3&amp;_z=z">This is the second sentence. </a></p>
    So what's the scoop?  I can't seem to figure out what's causing this problem.  I thought it might be carriage returns/line feeds in the selected HTML, but stripping the whitespace from both ends had no effect.  Any ideas?
     
    Thanks in advance,
     
    Geoffrey
     
View Complete Thread