-1

how to get the clicked or selected text from the web pages using javascript ??

How to get specific text like the mobile number or email

android_ar
  • 39
  • 5

1 Answers1

-1

This should work for you:

const getSelectionText = () => {
  let text = "";

  if (window.getSelection) {
    text = window.getSelection().toString();
  } else if (document.selection && document.selection.type != "Control") {
    text = document.selection.createRange().text;
  }

  return text;
}
Steven2105
  • 540
  • 5
  • 20