javascript - how to disable copy for particular element in html - Stack Overflow

Here, I'm having a problem with copy option when select 3 elements all the three are getting copie

Here, I'm having a problem with copy option when select 3 elements all the three are getting copied. But, I have a Jquery function to disable copy for the middle element. How I can disable that while selecting 3 elements. But, If I select the middle element individually it's not copying.

$('#notcp').bind('cut copy paste', function (e) {
    e.preventDefault();
});
<script src=".1.1/jquery.min.js"></script>
<p >
select and copy
</p>
<p id="notcp">
cannot copy
</p>
<p>
select and copy
</p>

Here, I'm having a problem with copy option when select 3 elements all the three are getting copied. But, I have a Jquery function to disable copy for the middle element. How I can disable that while selecting 3 elements. But, If I select the middle element individually it's not copying.

$('#notcp').bind('cut copy paste', function (e) {
    e.preventDefault();
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p >
select and copy
</p>
<p id="notcp">
cannot copy
</p>
<p>
select and copy
</p>

Share Improve this question asked May 26, 2017 at 11:53 Satya PendemSatya Pendem 3255 silver badges14 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Use This CSS Style to disable Selection. By this The Text will not be selected. Thus can't be copied also.

#notcp {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}

This feature can be done via disabling Text Selection using few CSS lines:

html, body {
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;
}

try add return false;

   $('#notcp').bind('copy paste',function(e) {
    e.preventDefault(); return false; 
});

Try with this.

$(document).on("cut copy paste","#notcp",function(e) {
    e.preventDefault();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743992933a4540127.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信