Reputation: 19651
problem with keypress (in jquery) with IE
$(document).keypress(function(key) {
if (key.which == 99 && key.metaKey == true) {
alert("Don't Copy");
return false;
}
});
It doesn't work !
How can I fix it ?
Upvotes: 0
Views: 1134
Reputation: 21763
I think you want to check the status of ctrlKey
to block Ctrl + C:
$(document).keydown(function(key) {
if (key.which == 67 && key.ctrlKey) {
alert("Don't Copy");
return false;
}
});
It does work on all major browsers (FF4b7, IE 8), but not entirely correct in Chrome 8: although the alert pops up, the copy-to-clipboard behaviour is not suppressed.
That said, if you want to prevent the user from copying your texts to the clipboard, I'll have to disappoint you: someone can simply use the (context) menu option or view your page's source. There's nothing that you can do about that.
Upvotes: 3
Reputation: 1659
why keypress?
$('*').bind('copy',function(key) {
alert("Don't Copy");
return false;
});
Upvotes: 2