I'm trying to run some code when the user presses control+c on a webpage, but I still want that key action to copy whatever the user has selected. With my current code, only the events I write actually happen and the default action is ignored.
Is this possible? Here's the code I'm using:
Code for control key functionality
$.ctrl = function(key, callback, args) {
var isCtrl = false;
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.ctrlKey) isCtrl = true;
if(e.keyCode == ke开发者_运维百科y.charCodeAt(0) && isCtrl) {
callback.apply(this, args);
return false;
}
}).keyup(function(e) {
if(e.ctrlKey) isCtrl = false;
});
};
Code for Control+C:
$('input').click(function(){
$(this).addClass('selected');
$(this).focus();
$(this).select();
});
$('input').blur(function(){
$('input.selected').removeClass('selected');
});
$.ctrl('C', function() {
if( $('input.selected').length != 0 )
{
alert("Saved");
}
});
Remove the line return false;
精彩评论