Window getSelection()Method

Window 对象参考手册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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 对象参考手册Window Object Other Extensions