Gets the currently selected text.
- Use
Window.getSelection()
andSelection.toString()
to get the currently selected text.
代码实现
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'
Gets the currently selected text.
Window.getSelection()
and Selection.toString()
to get the currently selected text.
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'