getSelectedText

Gets the currently selected text.

  • Use Window.getSelection() and Selection.toString() to get the currently selected text.
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'