Skip to content

Instantly share code, notes, and snippets.

@JBlond
Created June 9, 2017 12:11
Show Gist options
  • Save JBlond/10c5501f6c291dc11e0f3f74848d3b2e to your computer and use it in GitHub Desktop.
Save JBlond/10c5501f6c291dc11e0f3f74848d3b2e to your computer and use it in GitHub Desktop.
<h3>Ctrl+c Ctrl+v disabled</h3>
<textarea class="no-copy-paste"></textarea>
<br><br>
<h3>Ctrl+c Ctrl+v allowed</h3>
<textarea></textarea>
$(document).ready(function() {
var ctrlDown = false,
ctrlKey = 17,
cmdKey = 91,
vKey = 86,
cKey = 67;
$(document).keydown(function(e) {
if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = true;
}).keyup(function(e) {
if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = false;
});
$(".no-copy-paste").on({
keydown: function(event){
if(ctrlDown && (event.keyCode == vKey || event.keyCode == cKey)){
alert('GOT YA');
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment