This is a migrated thread and some comments may be shown as answers.

getting selected text in js.

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 19 Sep 2013, 12:15 PM
This is not a telerik specific query. When I select the text by double clicking or click and dragging, How can I get the selected text in js? 

Thankyou
Robert

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Sep 2013, 12:30 PM
Hi Robert,

Please check the following JavaScript.

JavaScript:
<script type="text/javascript">
    var searchString = "";
    if (window.document.selection) {
        var rng = window.document.selection.createRange();
        searchString = rng.text;
    }
    else if (window.getSelection) {
        searchString = window.getSelection().toString();
    }
</script>

Thanks,
Shinu.
Tags
General Discussions
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or