Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Window getSelection() method

Window getSelection() method

Window Object Reference 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 »


Window Object Reference Window Object