stmn stmn - 27 days ago 7x
Android Question

Disabling text selection in PhoneGap

Is it possible to disable text selection to make a PhoneGap app more similar to normal native app?

Something like this:

document.onselectstart = function() {return false;}


* {
user-select: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;

Or many other things don't work.


I looked all over for help on this. This finally worked for me.

public class MainActivity extends DroidGap {

    public void onCreate(Bundle savedInstanceState) {


        super.appView.setOnLongClickListener(new View.OnLongClickListener() {

            public boolean onLongClick(View v) {
                return true;

The setOnClickListener is what does the magic. Make sure you put this AFTER your call to super.loadUrl.

Of course, this will disable text selection for your entire app, but I'm OK with that, and I don't have any other way around it for now.

I'm not sure of the complete implications of this yet, but I do make use of the JqueryMobile event "taphold", and it still works fine. I believe this works by handling the long click on the appView (which hosts your HTML app) and preventing it from bubbling up.