由于在不同浏览器下对于ctrl+p的效果不同,有的还是能打印,并且使用浏览器上的打印也可以,再次更改
在页面头上加入以下代码,即使能打印也只是打印空白页面。
<style unselectable="on" style="-webkit-user-select: none; "> @media print { * { display: none } } </style>
(function($){ $.fn.ctrl = function(key, callback) { if(typeof key != 'object') key = [key]; callback = callback || function(){ return false; } return $(this).keydown(function(e) { var ret = true; $.each(key,function(i,k){ if(e.keyCode == k.toUpperCase().charCodeAt(0) && e.ctrlKey) { ret = callback(e); } }); return ret; }); }; $.fn.disableSelection = function() { $(window).ctrl(['a','s','c','p']); return this.each(function() { $(this).attr('unselectable', 'on') .css({'-moz-user-select':'none', '-o-user-select':'none', '-khtml-user-select':'none', '-webkit-user-select':'none', '-ms-user-select':'none', 'user-select':'none'}) .each(function() { $(this).attr('unselectable','on') .bind('selectstart',function(){ return false; }) .bind("contextmenu",function(){return false;}); }); }); }; })(jQuery); $(function(){$(document).disableSelection();});
下午3点更正,经测试,上面代码在ff中不能屏蔽select,经实验后,再加一上句js即可对执行语句进行更改,在ff上也能屏蔽
$(function(){$(document.body).disableSelection();});
下午5点更正,经测试,上面代码在ie下不能屏蔽ctrl+p,再加一句纯js来单独屏蔽ie下的打印快捷键
document.onkeydown=function(){if(event.ctrlKey&&event.keyCode==80){event.keyCode=0;event.returnValue=false;}}
---------------------------------------------------------------------------------------------------------------------------------
$(function(){ var target=document.body; if (typeof target.onselectstart!="undefined") //IE route target.onselectstart=function(){return false} else if (typeof target.style.MozUserSelect!="undefined") //Firefox route target.style.MozUserSelect="none" else //All other route (ie: Opera) target.onmousedown=function(){return false} target.style.cursor = "default"; $(document).bind("contextmenu",function(e){return false;}); });