Disable text selection and copy paste in hybrid app using JS

余生长醉 提交于 2019-12-06 02:18:10

问题


I am trying to disable text selection and copy paste in phonegap applicaion by using following code.

CSS

-webkit-user-select:none;

JavaScript

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

It works on all OS platforms including adroid 4.4+ but having issues on 4.1 and 4.2. Please Help.

Both doesn't support android 4.1.2 and 4.2.1.

[Tested on Micromax canvas 4 and samsung galaxy s2]


回答1:


you can use css to do that

*
{
-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;
}

found here Disable Copy and Paste in Phonegap




回答2:


Here is the solution I found and worked, but not through JS. Paste the following code in MainActivity.java file

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

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


来源:https://stackoverflow.com/questions/27615891/disable-text-selection-and-copy-paste-in-hybrid-app-using-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!