problem in IE with getSelectedHTML()

  •  02-18-2009, 12:37 PM

    problem in IE with getSelectedHTML()

    I am having a problem with getSelectedHTML() function in cute editor, asp version.
     
    I am trying to create my own link by selecting an image(gif, jpg or png) file and manipulating and inserting the link into the editor.
     
    When I select the image in Mozilla/Firefox, html in getSelectedHTML() function retruns correct details
       
             ex: 
      
    <IMG height="50" width="150" src="http://test.com/test/Clients/uploads/template-assets/logo-placeholder.gif" alt="" _moz_resizing="true"/>
     
    When I do it IE, I had to highlight the image(not select), to get the details. If I select image, it is returning blank html, why is it so.
     
    I noticed another thing that in getSelectedHTML(), When I use IE, it is going to if part and alerting 'test1' and going to else part and alerting 'test2' in case of Firefox.

    var editor1=document.getElementById("<%= editor.ClientID %>");

    function getSelectedHTML()
    {   
          var rng=null,html="";
          var editdoc = editor1.GetDocument();
         
    var editwin = editor1.GetWindow();
          if (document.selection && document.selection.createRange)
          {   
                rng=editdoc.selection.createRange();
                html=rng.htmlText||
    "";   
                alert(
    "test1");
          }
            else if (window.getSelection)
          {
                rng=editwin.getSelection();
                if (rng.rangeCount > 0 && window.XMLSerializer)
                {
                      rng=rng.getRangeAt(0);
                      html=
    new XMLSerializer().serializeToString(rng.cloneContents());
                }
                alert(
    "test2");
          }
             alert(html);
             return html;
    }

    please, Adam, help me out.
     
View Complete Thread