Re: Problem of GetSelection() in IE

  •  11-06-2008, 4:03 AM

    Re: Problem of GetSelection() in IE

    Hi Maximus
     
    We have the following code which we have been using to select text. This was on the forums a couple of years ago, I have tried the new example above and this seemed to work fine for me (altho I only did a quick test). Anyway hope the below helps.

     

    function getLinkHTML()
    {
      // get the cute editor instance
      var editor1 = document.getElementById('<%=Editor1.ClientID%>');
      // get the selected text or image etc..
      var editselection=editor1.GetSelection(); 
      var ret = "";
      // if firefox
      if(editselection.rangeCount > 0)
      {
        var range=editselection.getRangeAt(0);
        var clonedSelection = range.cloneContents();
        var div = document.createElement('div');
        div.appendChild(clonedSelection);
        ret = div.innerHTML;
      }
      // if IE
      else
      {
        var range=editselection.createRange();
        // If the selection is text
        if(editselection.type=='Text')
        {
          ret = range.htmlText;
        }
        if(editselection.type=='Control')
        {
          if(range.length==1)
          {
            var element=range.item(0);
            // If the selection is a image
            if(element.tagName=='IMG')
            {
              //gets all the html of the image tag to use in the link
              src = element.getAttribute("outerHTML") + '' ;
              ret = src;
            }
          }
        }
      }

      return ret;
    }

     

View Complete Thread