第一款带浮窗效果的代码:- <script type="text/javascript">
- window.onload = function() {
- //屏蔽键盘事件
- document.onkeydown = function() {
- var e = window.event || arguments[0];
- //F12
- if (e.keyCode == 123) {
- alert('兔源码网址:www.tuyuanma.com');
- return false;
- //Ctrl+Shift+I
- } else if ((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
- alert('兔源码网址:www.tuyuanma.com');
- return false;
- //Shift+F10
- } else if ((e.shiftKey) && (e.keyCode == 121)) {
- alert('兔源码网址:www.tuyuanma.com');
- return false;
- //Ctrl+U
- } else if ((e.ctrlKey) && (e.keyCode == 85)) {
- alert('兔源码网址:www.tuyuanma.com');
- return false;
- }
- };
- //屏蔽鼠标右键
- document.oncontextmenu = function() {
- alert('兔源码网址:www.tuyuanma.com');
- return false;
- }
- }
- </script>
复制代码 第二款直接禁止,无任何特效:- <script type="text/javascript">
- var arr = [123, 17, 18, 121];
- document.oncontextmenu = new Function("event.returnValue=false;"),//禁用右键
- window.onkeydown = function (e) {
- var keyCode = e.keyCode || e.which || e.charCode;
- var ctrlKey = e.ctrlKey || e.metaKey;
- console.log(keyCode + "--" + keyCode);
- if (ctrlKey && keyCode == 85) {
- console.log("ctrl+u");
- e.preventDefault();
- }
- if (arr.indexOf(keyCode) > -1) {
- console.log("其他");
- e.preventDefault();
- }
- //e.preventDefault();
- //return false;
- }
- </script>
复制代码 第三款屏蔽所有查看源代码方式(如dz论坛开启验证码,对验证码输入有较小影响):- <script type='text/javascript'>
- //禁用右键(防止右键查看源代码)
- window.oncontextmenu=function(){return false;}
- //禁止任何键盘敲击事件(防止F12和shift+ctrl+i调起开发者工具)
- window.onkeydown = window.onkeyup = window.onkeypress = function () {
- window.event.returnValue = false;
- return false;
- }
- //如果用户在工具栏调起开发者工具,那么判断浏览器的可视高度和可视宽度是否有改变,如有改变则关闭本页面
- var h = window.innerHeight,w=window.innerWidth;
- window.onresize = function () {
- if (h!= window.innerHeight||w!=window.innerWidth){
- window.close();
- window.location = "about:blank";
- }
- }
- </script>
复制代码 |