Re: Problem of GetSelection() in IE

  •  11-06-2008, 1:46 AM

    Re: Problem of GetSelection() in IE

    Hi Adam,
     
    I tried the code in IE. Please have a look and give a suggestion.
     
     
    Code:-
     
    var e1 = document.getElementById('<% =Editor1.ClientID%>');
    var editdoc = e1.GetDocument();
    var editwin = e1.GetWindow();
    var rng=null,html="";

     

    if (document.selection && document.selection.createRange){
    rng=editdoc.selection.createRange();
    html=rng.htmlText||"";      // htmlText is coming out to be blank.And this is the problem in IE.
    alert(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());
    }

    }

     

    alert(html);

     


    Karan Singh
    (Web Developer)
View Complete Thread