CuteEditor for ASP

Retrieves the HTML contained within the selection range

Retrieves the HTML contained within the range


In order to get the HTML contained within the selection range, you need to use the following code:


function getSelectedHTML(){
      // get the active editor window
      var editwin = editor1.GetWindow();

      // get the active editor document
      var editdoc = editor1.GetDocument();

      var rng=null,html="";

      if (document.selection && document.selection.createRange){
        rng=editdoc.selection.createRange();
        html=rng.htmlText||"";
      }else if (window.getSelection){
        rng=editwin.getSelection();

        if (rng.rangeCount > 0 && window.XMLSerializer){
          rng=rng.getRangeAt(0);
          html=new XMLSerializer().serializeToString(rng.cloneContents());
        }
      }
      return html;
 }