是否有可能禁用文本选择功能,使得 PhoneGap 应用程序更类似于正常的本地应用程序?
像这样:
document.onselectstart = function() {return false;}
或者:
* {
user-select: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
或者很多其他事情不起作用。
是否有可能禁用文本选择功能,使得 PhoneGap 应用程序更类似于正常的本地应用程序?
像这样:
document.onselectstart = function() {return false;}
或者:
* {
user-select: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
或者很多其他事情不起作用。
对我来说,将其放在html
上而不是*
上可以正常工作:
html {
-webkit-user-select: none;
}
我寻找了很多帮助,最终这个方法对我有用。
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应用程序)上的长按事件并防止其冒泡而实现的。
Cannot resolve method 'setOnLongClickListener' in 'CordovaWebView'
的问题。 - jinn<body oncontextmenu="return false" ondragstart="return false"
onselectstart="return false">
除了ThinkingStiff提到的之外,我也使用以下内容来删除任何高亮/复制&粘贴:
-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
<style type="text/css">
*:not(input,textarea) {
-webkit-touch-callout: none;
-webkit-user-select: none; /* Disable selection/Copy of UIWebView */
}
</style>
*:not(input):not(textarea)
。 - mtdb我使用了以下代码,在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;
}
对我来说,这是最好的:
-webkit-tap-highlight-color: rgba(0,0,0,0);
tap-highlight-color: rgba(0,0,0,0);
我的情况发生在pixi.js中,使用了
plugins.interaction.autoPreventDefault = true;
最近更新到Android 4.4 KitKat版本,它解决了Edittext在taphold(长按)时显示的问题。显然,在Android 4.4上,使用jquery mobile和phonegap时,edittext不会在taphold上出现。我正在使用自定义aosp rom,因此尚未在官方版本上进行测试,但我猜测(并希望)它也适用于任何4.4版本。它似乎还解决了我遇到的其他与onclick冲突的问题,如下所述。
我发现的旧方法(可能存在问题),适用于旧版ICS roms(仅在4.0.4自定义rom上测试过)。
通过添加滚动条
示例:
<div id="scroll">content</div>
<style>
#scroll {
height: 100%;
width: 100%;
}
</style>
* {
-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;
}
html { user-select: none;}
- math_lab3.ca