33

是否可以禁用文本选择以使 PhoneGap 应用程序更类似于普通的原生应用程序?

像这样的东西:

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

或者:

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

或者许多其他的东西不起作用。

4

9 回答 9

59

穿上它html,而不是*,对我有用:

html {
    -webkit-user-select: none;
}
于 2012-08-06T06:53:00.477 回答
32

我四处寻找帮助。这终于对我有用。

public class MainActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        super.loadUrl("file:///android_asset/www/index.html");

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

            public boolean onLongClick(View v) {
                return true;
            }
        });
    }
}

setOnClickListener 有什么魔力。确保在调用 super.loadUrl 之后放置它。

当然,这将禁用整个应用程序的文本选择,但我对此表示满意,而且我目前没有任何其他方法可以解决它。

我还不确定它的完整含义,但我确实使用了 JqueryMobile 事件“taphold”,它仍然可以正常工作。我相信这可以通过处理对 appView(托管您的 HTML 应用程序)的长按并防止它冒泡来实现。

于 2012-08-08T20:31:46.650 回答
9

这也可以。

<body oncontextmenu="return false" ondragstart="return false" 
onselectstart="return false">
于 2014-03-26T13:21:35.533 回答
8

除了 ThinkingStiff 提到的内容外,我还使用以下内容删除任何突出显示/复制和粘贴

-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0); 
于 2012-08-06T13:14:41.130 回答
6

添加这个并享受。也适用于 iOS。

<style type="text/css">
*:not(input,textarea) {
    -webkit-touch-callout: none;
    -webkit-user-select: none; /* Disable selection/Copy of UIWebView */
}
</style>
于 2015-10-14T05:56:56.907 回答
1

我使用了下面的代码,它在 Android 和 iOS 设备以及模拟器/模拟器上运行良好:

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

   input, textarea {
    -webkit-user-select: auto !important;
    -khtml-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
    user-select: auto !important;
    }
于 2017-09-04T03:59:19.080 回答
0

最近更新到 Android 4.4 kitkat,它解决了 Edittext 在点击(长按)时出现的问题。显然edittext没有出现在带有jquery mobile和android 4.4上的phonegap的taphold上。我正在使用自定义 aosp rom,因此尚未在官方版本上进行测试,但我猜测(并希望)它应该适用于任何 4.4 版本。它似乎也解决了我在下面发布的 onclick 的其他冲突。

我发现较旧的方法适用于较旧的 ICS rom(仅在 4.0.4 自定义 rom 上测试)。
通过添加滚动条

例子:

<div id="scroll">content</div> 

<style>
#scroll {

height: 100%;
width: 100%;
}
</style>

它还禁止 EditText 在 phonegap 和 jquery mobile 上弹出点击(长按)。尚不确定这是否会导致任何冲突(似乎对正在整理的 onclick 有一些影响),但使用常规文本应该可以正常工作。--- 使用 Android 4.4 解决的问题并且不再需要滚动。(见帖子顶部)

于 2014-04-24T17:02:43.530 回答
0

对我来说这是最好的:

-webkit-tap-highlight-color: rgba(0,0,0,0); 
tap-highlight-color: rgba(0,0,0,0);

我的案例发生在 pixi.js 上,与

plugins.interaction.autoPreventDefault = true;
于 2016-09-26T15:04:37.203 回答
-1
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none; 
}

[contenteditable="true"] , input, textarea {
    -webkit-user-select: auto !important;
    -khtml-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
    -o-user-select: auto !important;
    user-select: auto !important;  
}
于 2017-04-23T20:27:54.387 回答