problem with GetSelection() in IE

Last post 11-14-2008, 2:36 AM by Laurent31. 3 replies.
Sort Posts: Previous Next
  •  11-13-2008, 7:02 AM 45685

    problem with GetSelection() in IE

    Hi
     
    There is a bug when using GetSelection() function with IE. Try with your demo page "Add custom buttons (Pop-up)" with a small modification into "My_Custom_Text.html" file : Modify the script "button_click()" as follow :
        function button_click() {
            var editor=Window_GetDialogArguments(window);
            var mySelectedText = editor.GetSelection();
            alert(mySelectedText);
            //var ta=document.getElementById("ta");
            //editor.PasteHTML(ta.value);
        }


    Refresh the demo page, write a text and select it into the wysiwyg ... then push the personnalized button and click on "Insert it".
    In FF, an alert is display with your selected text
    In IE, an alert is display with "[object]" ... :-(
     
    I need this function to insert the selected text into a personnalised link included into our CMS !
     
    Thank's to help me.
     
    Laurent - Toulouse, France
  •  11-13-2008, 11:09 AM 45695 in reply to 45685

    Re: problem with GetSelection() in IE

    Laurent,
     
    The selection is an object. So it's nothing wrong.
     
    Please use the following code:
     
     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;
        }

     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  11-13-2008, 4:50 PM 45709 in reply to 45695

    Re: problem with GetSelection() in IE for custom button with popup

    Adam,
     
    I saw the thread 37318 which speaks about this function getSelectedHTML() integrated into a personnalised button ... but not into a dialog. Can you please tell us for example how you integrate this function into the demo page "Add cutom dialogs" please ?
     
    Thank's
    Laurent - Toulouse, France
  •  11-14-2008, 2:36 AM 45721 in reply to 45709

    Re: problem with GetSelection() in IE for custom button with popup

    This solution seems to work :
     
    function getSelectedHTML() {
        var editor1 = Window_GetDialogArguments(window)
        var editdoc = editor1.GetDocument();
        var editwin = editor1.GetWindow();
        var rng=null, html="";
        if (document.selection && document.selection.createRange) {
            rng=editdoc.selection.createRange();
            html=rng.htmlText;
            if(html == undefined) {
                html = rng.item(0).outerHTML;
            }
        }
        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 as RSS news feed in XML