problem in IE with getSelectedHTML()

Last post 02-18-2009, 3:38 PM by Adam. 1 replies.
Sort Posts: Previous Next
  •  02-18-2009, 12:37 PM 48944

    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.
     
  •  02-18-2009, 3:38 PM 48963 in reply to 48944

    Re: problem in IE with getSelectedHTML()

    1. function getSelectedHTML()   
    2. {      
    3.       var rng=null,html="";   
    4.       var editdoc = editor1.GetDocument();   
    5.       var editwin = editor1.GetWindow();   
    6.       if (document.selection && document.selection.createRange)   
    7.       {      
    8.             rng=editdoc.selection.createRange();   
    9.         if( rng.htmlText )    
    10.             {    
    11.         html=rng.htmlText;    
    12.         }    
    13.         else if(rng.length >= 1)    
    14.         {    
    15.               html=rng.item(0).outerHTML;    
    16.             }   
    17.       }   
    18.         else if (window.getSelection)   
    19.       {   
    20.             rng=editwin.getSelection();   
    21.             if (rng.rangeCount > 0 && window.XMLSerializer)   
    22.             {   
    23.                   rng=rng.getRangeAt(0);   
    24.                   html=new XMLSerializer().serializeToString(rng.cloneContents());   
    25.             }   
    26.       }   
    27.       return html;   
    28. }  

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML