-1

If a user select some text from the article of a webpage then show share and copy button for the following selected text. I want to do something like this.. the guardian

1 Answers1

1

There is no inbuilt event for text selection but you can use

onmouseup this would be invoked whenever user releases his left mouse button. After every such event we can check if the user has selected any text or not
window.getSelection() to test for any text selection. If the selected text is not an empty string, you can invoke your function which would show up required buttons

Here is an example with code (note - uses jQuery)

SOURCE

Community
  • 1
  • 1
ArmaGeddON
  • 339
  • 1
  • 10