Working with GetSelection in IE

Last post 07-25-2007, 3:53 PM by toheDeveloper. 2 replies.
Sort Posts: Previous Next
  •  07-25-2007, 9:53 AM 31850

    Working with GetSelection in IE

    I have the following javascript code that executes when a custom toolbar button is clicked:

    function insertLink(sender)

    {

    var cuteEditor = CuteEditor_GetEditor(sender);

    var selection = cuteEditor.GetSelection();

    cuteEditor.PasteHTML('<a href="http://www.google.com" target="_blank">' + selection + '</a>');

    }

    In Firefox, this works the way I expected - the selected text in the editor becomes a hyperlink. However, in IE (specifically IE7), the selected text is replaced by "[object]" which becomes the hyperlink.
     
    Using Firebug to step through the code I see that the GetSelection() function does not just return a string but a javascript object. So my ultimate question is how do I use javascript to get access to just the selected text in IE.
     
    Thank you,
    Richard
  •  07-25-2007, 1:51 PM 31877 in reply to 31850

    Re: Working with GetSelection in IE

    Richard,
     
    In IE, selection is an object. Please use the following code to extract HTML code from selection object.
     

        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        var editselection=editor1.GetSelection();  
        var r= editselection.createRange();

        alert(r.htmlText); // get a selected HTML text

    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

  •  07-25-2007, 3:53 PM 31884 in reply to 31877

    Re: Working with GetSelection in IE

    Thanks.
     
    Richard
View as RSS news feed in XML