Prevent WebView text selection

You must Login before you can answer or comment on any questions.

Is there a way to reliably prevent webview text selection? (I'm testing this specifically on Android.)

I've seen advice (for iPhone) to use -webkit-user-select: none; for the CSS of (for instance) the body element, but that doesn't seem to do it for Android. I'm still able to select within the webview.

Unfortunately that causes some ugly crashing in this app.

— asked 11 months ago by K T
1 Comment
  • use this----->

    webview.addEventListener('longpress', function(e) { return false; });

    webview.addEventListener('longclick', function(e) { return false; });

    — commented 8 months ago by Arun Shejul

2 Answers

please use this------->

webview.addEventListener('longpress', function(e) { alert("you can't select text...!"); });

use this----->

webview.addEventListener('longpress', function(e) { return false; });

webview.addEventListener('longclick', function(e) { return false; });

Your Answer

Think you can help? Login to answer this question!