Re: Problems with editor.GetSelection() in IE

  •  05-20-2008, 4:01 PM

    Re: Problems with editor.GetSelection() in IE

    Man, I've been fighting for three days to get the getSelectedHTML() function to work for me!! I'm aware of the need to create the above variables before calling the function, but I still can't make it work for me.
     
    In the past I've successfully installed a number of wysiwyg editors (wysiwygPro, TinyMCE, etc.) and set up custom buttons so I can select text, modify it, and insert the modified text back into the editor window, but I can't seem to do it with CuteEditor. It would sure be helpful if there was a complete example like this from your documentation, but that showed in similar detail how to set up a custom button that will select text. The snippets of code you provide here and there are insufficient. Why isn't there a complete example in the documentation?? Selecting text is pretty fundamental to any similar kind of editor.
     
    I'm aware of this piece of code, but how is it used? I thought I understood how, but try as I might, it's not working:
     
    function getSelectedHTML(){
          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;
        }
     
View Complete Thread