Reputation: 1911
Here's the code I'm using and the methods I've tried already, they work in Chrome and Firefox:
$j(document).on('keydown', function (e) {
if(e.keyCode == 80) {
if(ctrl_key == 'yes') {
do_something();
e.preventDefault();
e.stopPropagation();
e.cancelBubble = true;
}
}
});
$j(document).on('keypress keyup', function (e) {
if(e.keyCode == 80) {
if(ctrl_key == 'yes') {
e.preventDefault();
e.stopPropagation();
e.cancelBubble = true;
}
}
});
This is for the print function (ctrl + p)
Is there any way top stop this behavior?
Upvotes: 2
Views: 1558
Reputation: 14025
Cross-browsers method :
$j(document).on('keydown', function (e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(e.ctrlKey && key == 80) {
e.preventDefault();
e.stopPropagation();
alert("CTRL + P pressed");
return false;
}
});
You need to select the "document", click in the render panel or in the edit box before test http://jsfiddle.net/PTauw/99/
Upvotes: 2