H5_0003:JS禁用调试,禁用右键,监听F12事件的方法
1,禁用调试
// 这个方法是防止恶意调试的
(function () {
console["log"]("================================设置控制台界面变化事件");
'use strict';
var devtools = {
open: false,
orientation: null
};
// inner大小和outer大小超过threshold被认为是打开了开发者工具
var threshold = 160;
// 当检测到开发者工具后发出一个事件,外部监听此事件即可,设计得真好,很好的实现了解耦
var emitEvent = function (state, orientation) {
window.dispatchEvent(new CustomEvent('devtoolschange', {
detail: {
open: state,
orientation: orientation
}
}));
};
// 每500毫秒检测一次开发者工具的状态,当状态改变时触发事件
setInterval(function () {
var widthThreshold = window.outerWidth - window.innerWidth > threshold;
var heightThreshold = window.outerHeight - window.innerHeight > threshold;
var orientation = widthThreshold ? 'vertical' : 'horizontal';
// 第一个条件判断没看明白,heightThreshold和widthThreshold不太可能同时为true,不论是其中任意一个false还是两个都false取反之后都会为true,此表达式恒为true
if (!(heightThreshold && widthThreshold) &&
// 针对Firebug插件做检查
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) {
// 开发者工具打开,如果之前开发者工具没有打开,或者已经打开但是靠边的方向变了才会发送事件
if (!devtools.open || devtools.orientation !== orientation) {
emitEvent(true, orientation);
};
console["log"]("================================控制台已打开响应跳转事件");
//打开官网
mA();
devtools.open = true;
devtools.orientation = orientation;
} else {
// 开发者工具没有打开,如果之前处于打开状态则触发事件报告状态
if (devtools.open) {
emitEvent(false, null);
}
// 将标志位恢复到未打开
devtools.open = false;
devtools.orientation = null;
}
}, 500);
if (typeof module !== 'undefined' && module.exports) {
module.exports = devtools;
} else {
window.devtools = devtools;
};
//禁用右键 oncontextmenu
document["\u006f\u006e\u0063\u006f\u006e\u0074\u0065\u0078\u0074\u006d\u0065\u006e\u0075"] = function () {
console["log"]("================================设置禁用右键");
return false;
};
//鼠标右键点击事件 onmousedown
document["\u006f\u006e\u006d\u006f\u0075\u0073\u0065\u0064\u006f\u0077\u006e"] = function mc(event) {
console["log"]("================================设置禁用右键点击");
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e.button == 2 || e.button == 3) {
return false;
}
}
//监听键盘F12事件 onkeydown ,onkeyup,onkeypress
document["\u006f\u006e\u006b\u0065\u0079\u0064\u006f\u0077\u006e"] = document["\u006f\u006e\u006b\u0065\u0079\u0075\u0070"] = document["\u006f\u006e\u006b\u0065\u0079\u0070\u0072\u0065\u0073\u0073"] = function (event) {
console["log"]("================================设置监听键盘F12事件");
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 123) {
mA();
e.returnValue = false;
return (false);
}
};
function mA() {
console["log"]("================================设置开启调试事件响应方法");
//window.location.href = "http://www.3dplus.cn/cn";
location['href'] = "http://www.baidu.com";
}
})();
H5_0003:JS禁用调试,禁用右键,监听F12事件的方法的更多相关文章
- 使用 JS 关闭警告框及监听自定义事件(amaze ui)
使用 JS 关闭警告框及监听自定义事件(amaze ui) 一.总结 1.jquery匿名函数:第8行,jquery匿名函数,$(function(){});,有没有很简单,只是少了jquery的前面 ...
- Js实现回车登录,监听回车事件
需求 项目有个回车登录功能,在此记录下 实现 我们应该监听当前登录页面的所有回车操作. $("body").keydown(function () { var yzmStatus ...
- DialogFragment 监听按键事件的方法(onkeydown)
我们在TV软件开发的时候,会使用DialogFragment,有时候要对它的按键事件进行监听,但是DialogFragment的监听方法和其它的不一样. ...
- 两种js监听滚轮事件的方式
前段时间在写前端的时候,需要监听浏览器的滚轮事件 网上查了一下,找到两种监听滚轮事件的方法: 一.原生js通过window.onscroll监听 //window.onscroll = functio ...
- [JS]笔记12之事件机制--事件冒泡和捕获--事件监听--阻止事件传播
-->事件冒泡和捕获-->事件监听-->阻止事件传播 一.事件冒泡和捕获 1.概念:当给子元素和父元素定义了相同的事件,比如都定义了onclick事件,点击子元素时,父元素的oncl ...
- js 事件监听 冒泡事件
js 事件监听 冒泡事件 的取消 [自己写框架时,才有可能用到] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitiona ...
- 原 JS监听回车事件
原 JS监听回车事件 发表于2年前(2014-06-04 10:16) 阅读(6101) | 评论(0) 11人收藏此文章, 我要收藏 赞0 1月16日厦门 OSC 源创会火热报名中,奖品多多哦 ...
- JS 中的事件绑定、事件监听、事件委托
事件绑定 要想让 JavaScript 对用户的操作作出响应,首先要对 DOM 元素绑定事件处理函数.所谓事件处理函数,就是处理用户操作的函数,不同的操作对应不同的名称. 在JavaScript中,有 ...
- js 对于回车时间的监听,提交表单
// ------ 监听回车事件 -----------------// document.onkeydown=keyDownSearch; function keyDownSearch(e) { / ...
随机推荐
- django apscheduler在特定时间执行一次任务(run at a specify time only once)
如何使程序在特定时间只执行一次,我查了一下. celery可以,时间以秒计. task = mytask.apply_async(args=[10, 20], countdown=60) 不过,我 ...
- vue(3)—— vue的全局组件、局部组件
组件 vue有局部组件和全局组件,这个组件后期用的会比较多,也是非常重要的 局部组件 template与components属性结合使用挂载 其中 Vmain.Vheader.Vleft.Vconte ...
- Linux学习历程——SUID、SGID、SBIT简介
一.SUID.SGID.SBIT简介 SUID:对一个可执行文件,不是以发起者身份来获取资源,而是以可执行文件的属主身份来执行.SGID:对一个可执行文件,不是以发起者身份来获取资源,而是以可执行文件 ...
- Windows 2008 R2 域控制器迁移至windows 2016记录
文章参考 https://social.technet.microsoft.com/Forums/zh-CN/21a5f5e9-feee-4454-acad-fd22989d7bed/22495296 ...
- Web Storage:浏览器端数据储存机制
目录 概述 操作方法 存入/读取数据 清除数据 遍历操作 storage事件 参考链接 概述 这个API的作用是,使得网页可以在浏览器端储存数据.它分成两类:sessionStorage和localS ...
- Spring Boot自定义Banner
在2016年的最后一天,借用Spring Boot的Banner向各位程序猿同仁们问候一声:Happy New Year. 接下来我们就来介绍一下这个轻松愉快的自定义banner功能.实现的方式非常简 ...
- webpack优化相关操作
1.缩小文件搜索的范围 • 优化loader配置 尽量精确使用 include 只命中需要的文件. module.exports = { module: { rules: ...
- css文字与排版
目录 文字与排版样式 `font文字样式 排版样式(text) 文字半透明 文字阴影 背景和颜色 基本 背景简写 背景透明 背景缩放 列表样式 表格样式 表格边框样式 折叠边框 设置宽度和高度 表格对 ...
- dell服务器raid设置
dell服务器raid设置 配置说明: 开机自检按ctrl+R键进入配置界面 如果服务器有raid卡,而不想做磁盘阵列时,需要做单盘RAID0,主要是为了让卡来识别一下硬盘 对raid进行操作很可能会 ...
- Tomcat FAIL - Deploy Upload Failed, Exception: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (110960596) exceeds the confi
https://maxrohde.com/2011/04/27/large-war-file-cannot-be-deployed-in-tomcat-7/ Go to the web.xml of ...