Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Ctrl C/V using javascript for both internet explorer and firefox browsers

Tags:

javascript

I am making this javascript code in order to disable Ctlr+c and Ctlr+v, prenscreen, ALT+TAB, Ctlr+S, and PrintScreen keys.

<html>
<head>
<script language="javascript">

function Disable_Control_C() {
var keystroke = String.fromCharCode(event.keyCode).toLowerCase();

if (event.ctrlKey && (keystroke == 'c' || keystroke == 'v')) {
alert("let's see");
event.returnValue = false; // disable Ctrl+C
}
}

</script>
</head>
<body onkeydown="javascript:Disable_Control_C()">
Hello World!
</body>
</html>

unfortunately, code is working on IE browser, but not working on firefox. Can anyone here advice?

like image 404
Ali Taha Ali Mahboub Avatar asked Mar 13 '13 19:03

Ali Taha Ali Mahboub


2 Answers

  • I don't like when browsers do this to me, and
  • It's easy to work around, and
  • This doesn't count as "secure" by any definition, but

Use element.on(?:copy|cut|paste)

<body oncopy="return false" oncut="return false" onpaste="return false">
like image 144
Matt Ball Avatar answered Sep 18 '22 05:09

Matt Ball


you can use it jquery for this. You just need to bind the cut, copy and paste function with your element.

And add this Jquery script:

$(document).ready(function() {
    $('#Selector').bind('copy paste', function(e) {
        e.preventDefault();
    });
});
like image 39
Sachin Avatar answered Sep 17 '22 05:09

Sachin