Window getSelection()Method
Window Object
Definition and Usage
The getSelection() method represents the text range selected by the user or the current position of the cursor.
Syntax
window.getSelection();
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the focus() method
Example
Example
Read the selected content:
function foo() {
let selObj = window.getSelection();
alert(selObj.toString());
}
Try it Yourself »
Window Object Other Extensions