Disabling text selection popup menu without disabling selection altogether

Viewed 142

I'm developing a custom e-reader app. I would like to make a custom highlighting menu, but I'm having trouble disabling the "Copy/Paste/Share" menu that pops up when text is selected on mobile devices. As far as I have researched, it seems impossible to disable without disabling selection altogether. But I wonder if by chance anyone has found a workaround.

I am aware of user-select: none which disables all selection. This is not desirable for me because I will need to access the javascript selection API for saving highlights, among other things.

Thanks!

1 Answers

Doesn't listen for contextmenu event and cancel it - work for you? It works for me on Android phone.

window.addEventListener("contextmenu", e =>
{
  e.preventDefault();
  console.log("selected text:", window.getSelection().toString());
});
some text

Related