如何在浏览器中使用jquery禁用Ctrl + A(全选)? [英] How can I disable Ctrl+A (select all) using jquery in a browser?
本文介绍了如何在浏览器中使用jquery禁用Ctrl + A(全选)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试阻止从页面复制信息(当然是针对非技术用户).我知道如何使用鼠标禁用选择文本.以下jquery代码有效:
I'm trying to prevent information to be copied from a page (for non-technical users of course). I know how to disable selecting text using the mouse. The following jquery code works:
$(function(){
$.extend($.fn.disableTextSelect = function() {
return this.each(function(){
if($.browser.mozilla){//Firefox
$(this).css('MozUserSelect','none');
}else if($.browser.msie){//IE
$(this).bind('selectstart',function(){return false;});
}else{//Opera, etc.
$(this).mousedown(function(){return false;});
});
});
$('.noSelect').disableTextSelect();
});
但是用户仍然可以使用Ctrl + A选择整个页面.有任何解决方法吗?
But users can still use Ctrl+A to select the entire page. Any workarounds for this?
推荐答案
此代码适用于您想要的ctrl + key的每种组合 65是ASCII码"A"
this code works for every combination of ctrl+key you want 65 is the ascii code of 'A'
如果您还要检查'a',请添加97
add 97 if you want to check also for 'a'
$(function(){
$(document).keydown(function(objEvent) {
if (objEvent.ctrlKey) {
if (objEvent.keyCode == 65) {
objEvent.disableTextSelect();
return false;
}
}
});
});
应该可以,我无需测试即可直接编写..
Should works, I wrote it directly without testing..
这篇关于如何在浏览器中使用jquery禁用Ctrl + A(全选)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文