title | tags |
---|---|
getSelectedText |
browser,beginner |
Get the currently selected text.
- Use
window.getSelection()
andSelection.prototype.toString()
to get the currently selected text.
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'