Home / Snippets / How to Get the User Selection Text on a Web Page
How to Get the User Selection Text on a Web Page cover

How to Get the User Selection Text on a Web Page

118

2 years ago

0 comments

If you want to get the text that a user selects or highlights on a web page, there is a useful one-liner for that and it's making use of the "window.getSelection" way.
const getSelectedText = () => window.getSelection().toString();

console.log(getSelectedText());
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this