【问题标题】:Disable text selection and copy paste in hybrid app using JS使用 JS 在混合应用程序中禁用文本选择和复制粘贴
【发布时间】:2015-02-21 07:57:32
【问题描述】:

我正在尝试使用以下代码在 phonegap 应用程序中禁用文本选择和复制粘贴。

CSS

-webkit-user-select:none;

JavaScript

$('body').on('cut copy paste',function(e){e.preventDefault();});

它适用于所有操作系统平台,包括 adroid 4.4+,但在 4.1 和 4.2 上存在问题。请帮忙。

两者都不支持 android 4.1.2 和 4.2.1。

[在 Micromax canvas 4 和三星 Galaxy s2 上测试]

【问题讨论】:

  • 使用简单的正文{ -webkit-touch-callout: none; -webkit-用户选择:无; }

标签: cordova copy paste textselection


【解决方案1】:

你可以使用 css 来做到这一点

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

input
{
-webkit-user-select: auto !important;
-khtml-user-select: auto !important;
-moz-user-select: auto !important;
-ms-user-select: auto !important;
user-select: auto !important;
}

在这里找到Disable Copy and Paste in Phonegap

【讨论】:

  • 当我使用上述代码[适用于 android 4.1 和 4.2] 时,输入占位符消失,用户无法在其中输入任何值。 android 4.1 和 4.2 的任何其他解决方案
  • 您还需要将 textarea 添加到第二个样式声明中
【解决方案2】:

这是我找到并工作的解决方案,但不是通过 JS。将以下代码粘贴到 MainActivity.java 文件

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

            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                return true;
            }
});

【讨论】:

  • 使用科尔多瓦,我没有找到 super.appView.setOnLongClickListener 的符号
猜你喜欢
  • 2018-01-19
  • 2017-07-15
  • 2021-07-16
  • 1970-01-01
  • 2019-07-11
  • 2011-04-18
  • 2017-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多