I'm trying to detect when the user presses Ctrl + V in JavaScript.
jQuery(document).on('paste', function() {alert('text pasted!')})
It works well with Chrome (v37). But it does not work with Firefox (v32) and IE (v11), as you can try on this jsfiddle:
http://jsfiddle.net/7N6Xq/410/
Any idea what I'm doing wrong?
EDIT - 2014-09-17 - need the clipboard content.
I cannot just rely on key detection, because I need the clipboard content which is only available through a paste event (there is no clean other way to access it). In this JSFiddle, I get the event and display the text (works on Chrome only)
http://jsfiddle.net/7N6Xq/412/
My final goal is to get an image from the clipboard and directly send it to the server.
To detect Ctrl+V, Ctrl+C using JavaScript, we can listen to the keyup and keydown events. let ctrlActive = false; let cActive = false; let vActive = false; document. body. addEventListener("keyup", (event) => { if (event.
It indicates if Ctrl was pressed at the time of the event, like this: $(document). keypress("c",function(e) { if(e. ctrlKey) alert("Ctrl+C was pressed!!"); });
To disable "Ctrl + C" put this script. function keypressed() {;return false;}document.
This is my JSFIDDLE. It worked well on Chrom & Firefox &IE10 Here is code:
$(document).keydown(function (event) {
if (event.ctrlKey && event.keyCode == 86) {
alert("!");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With