Results 1 to 3 of 3

Thread: Get Selected Text In Text Area In Internet Explorer

  1. #1

    Default Get Selected Text In Text Area In Internet Explorer


    I have a problem here that I can't seem to solve... I took over a 3.x project and there is a custom extension for the HTML Editor for text areas that provided additional functionality for the URL (hyperlink) button...

    In order to execute the additional functionality the extension needs to get the selected text in the text area... It works fine for Firefox, Safari and Chrome but it does not work for IE.

    Here's the current code that gets the text selection:

    win = this.getWin();
    var sel = win.getSelection ? win.getSelection() : win.document.selection;

    IE does not return the text... I have tried these suggested solutions for IE:

    still no go...

    Can anybody help ?

    Thanks in advance for your help !!!

    - M

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL


    This should work on IE:

    text = (document.all) ? document.selection.createRange().text : document.getSelection();
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:

    Posts are my own, not any current, past or future employer's.

  3. #3


    @mitchellsimoens : thanks for your reply !

    I tried your solution and it does not work for any browser in the Ext JS 3.x project.

    In a standalone simple test text area (plain HTML with an attached JavaScript function) your solution returns the selected text in IE but not in FF, Safari and Chrome...

    Btw, I noticed with my solution up top that on IE the selected text gets un-selected when it processes it and tries to get the text selection... that does not happen in any of the other browsers...

    Could that be the reason why it is returning an empty string ?


    - M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts