首页 > 代码库 > jquery禁用右键、文本选择功能、复制按键的实现
jquery禁用右键、文本选择功能、复制按键的实现
同时适合IE、firefox、谷歌浏览器下适用,经过筛选代码如下
//禁用右键、文本选择功能、复制按键 $(document).bind(“contextmenu”,function(){return false;}); $(document).bind(“selectstart”,function(){return false;}); $(document).keydown(function(){return key(arguments[0])}); //按键时提示警告 function key(e){ var keynum; if(window.event){ keynum = e.keyCode; // IE }else if(e.which){ keynum = e.which; // Netscape/Firefox/Opera } if(keynum == 17){ alert(“禁止复制内容!”); return false; } } //禁用右键、文本选择功能、复制按键 $(document).bind("contextmenu",function(){return false;}); $(document).bind("selectstart",function(){return false;}); $(document).keydown(function(){return key(arguments[0])}); //按键时提示警告 function key(e){ var keynum; if(window.event) // IE { keynum = e.keyCode; } else if(e.which) // Netscape/Firefox/Opera { keynum = e.which; } if(keynum == 17){ alert("禁止复制内容!");return false;} } <script> //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 function document.oncontextmenu(){event.returnValue=http://www.mamicode.com/false;}//屏蔽鼠标右键 function window.onhelp(){return false} //屏蔽F1帮助 function document.onkeydown(){ if((window.event.altKey)&& ((window.event.keyCode==37)|| //屏蔽Alt+方向键← (window.event.keyCode==39))){ //屏蔽Alt+方向键→ alert("不准你使用ALT+方向键前进或后退网页!"); event.returnValue=false; } if((event.keyCode==8)|| //屏蔽退格删除键 (event.keyCode==116)|| //屏蔽F5刷新键 (event.ctrlKey && event.keyCode==82)){ //Ctrl+R event.keyCode=0; event.returnValue=false; } if(event.keyCode==122){event.keyCode=0;event.returnValue=http://www.mamicode.com/false;} //屏蔽F11 if(event.ctrlKey && event.keyCode==78)event.returnValue=http://www.mamicode.com/false; //屏蔽Ctrl+n if(event.shiftKey && event.keyCode==121)event.returnValue=http://www.mamicode.com/false; //屏蔽shift+F10 if(window.event.srcElement.tagName=="A" && window.event.shiftKey) window.event.returnValue=false; //屏蔽shift加鼠标左键新开一网页 if((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); return false; } } </script>
<iframe id="google_ads_frame2" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1401222797&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3755329.html&dt=1401222800399&shv=r20140520&cbv=r20140417&saldr=sb&correlator=1401222800223&frm=20&ga_vid=1304086684.1400769066&ga_sid=1401204879&ga_hid=225578790&ga_fc=1&u_tz=480&u_his=613&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=0&ady=1681&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=2&xpc=XxDN47NCQ2&p=http%3A//www.cnblogs.com&dtd=51" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame2" marginWidth="0" scrolling="no" hspace="0"></iframe><iframe id="google_ads_frame3" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1401222797&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3755329.html&dt=1401222800458&shv=r20140520&cbv=r20140417&saldr=sb&prev_slotnames=8660799060&correlator=1401222800223&frm=20&ga_vid=1304086684.1400769066&ga_sid=1401204879&ga_hid=225578790&ga_fc=1&u_tz=480&u_his=613&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=304&ady=1931&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=3&xpc=POL2DkqORe&p=http%3A//www.cnblogs.com&dtd=47" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame3" marginWidth="0" scrolling="no" hspace="0"></iframe>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。