Re: Problems with editor.GetSelection() in IE

  •  05-21-2008, 10:41 AM

    Re: Problems with editor.GetSelection() in IE

    Thanks for the response, Adam, but your code doesn't work in Firefox. It works in IE 7 though. I've not tested it in anything else yet. Below is a link to the page where I'm running your code, and below that is the exact code I'm using:
     
     
     
    <?php include_once("CuteEditor_Files/include_CuteEditor.php") ; ?><html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>

    <form>
    <?php

    $editor=new CuteEditor();
    $editor->ID="Editor1";
    $editor->Text="Type here..";
    $editor->FilesPath="CuteEditor_Files";
    $editor->TemplateItemList="G_start,Bold,Italic,Underline,Separator,JustifyLeft,JustifyCenter,JustifyRight,G_end";
    $editor->CustomAddons = "<img title=\"Using oncommand\" class=\"CuteEditorButton\" onmouseover=\"CuteEditor_ButtonCommandOver(this)\" onmouseout=\"CuteEditor_ButtonCommandOut(this)\" onmousedown=\"CuteEditor_ButtonCommandDown(this)\" onmouseup=\"CuteEditor_ButtonCommandUp(this)\" ondragstart=\"CuteEditor_CancelEvent()\" Command=\"MyCmd\" src=\"CuteEditor_Files/Images/contact.gif\" />";
    $editor->Draw();

    $ClientID=$editor->ClientID();
    $editor=null;

    ?>

    <br />
    <input type="submit" value="Submit" ID="Submit1" NAME="Submit1" /><br />
    </form>


    <script language="JavaScript" type="text/javascript" >
    function CuteEditor_OnCommand(editor,command,ui,value)
    {
       // get the cute editor instance
       var editor1 = document.getElementById('CE_Editor1_ID');

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

       //handle the command by yourself
       if(command=="MyCmd")
       {
          alert(getSelectedHTML());
          editor1.PasteHTML("Hello World"+ getSelectedHTML());
          return true;
       }

       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;
        }
    }
    </script>




    </body>
    </html>

View Complete Thread