当前位置:网站首页>js禁止浏览器默认事件
js禁止浏览器默认事件
2022-06-25 16:44:00 【来陪人家玩游戏嘛】
禁止使用tab按键
_initStopTabKeycode () {
window.addEventListener('keydown', event => {
if (event.keyCode === 9) {
event.preventDefault()
}
})
}
PC端禁止浏览器放大缩小
_initNoScroll () {
const keyCodeMap = {
// 91: true, // command
61: true,
107: true, // 数字键盘 +
109: true, // 数字键盘 -
173: true, // 火狐 - 号
187: true, // +
189: true, // -
};
// 覆盖ctrl||command + ‘+’/‘-’
document.onkeydown = function (event) {
const e = event || window.event;
const ctrlKey = e.ctrlKey || e.metaKey;
if (ctrlKey && keyCodeMap[e.keyCode]) {
e.preventDefault();
} else if (e.detail) {
// Firefox
event.returnValue = false;
}
};
// 覆盖鼠标滑动
document.body.addEventListener('wheel', (e) => {
if (e.ctrlKey) {
if (e.deltaY < 0) {
e.preventDefault();
return false;
}
if (e.deltaY > 0) {
e.preventDefault();
return false;
}
}
}, {
passive: false });
}
禁止浏览器使用右键
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
})
- 需要查看如何自定义右键,可以查看我的文章 : 如何自定义右键
边栏推荐
- The role of the project manager in the project
- Wireshark network card cannot be found or does not display the problem
- 计网 | 形象理解路由协议RIP、OSPF、BGP
- 2022-06-17 网工进阶(十)IS-IS-通用报头、邻接关系的建立、IIH报文、DIS与伪节点
- On Web 3.0
- 剑指 Offer II 012. 左右两边子数组的和相等
- Ad domain login authentication
- Solution to the problem of incorrect clock in FreeRTOS kernel
- try with resource
- 【剑指 Offer II 091. 粉刷房子】
猜你喜欢
随机推荐
Redis series - overview day1-1
Optimization of lazyagg query rewriting in parsing data warehouse
[Jianzhi offer II 091. painting the house]
【无标题】
Kalman filter meets deep learning: papers on Kalman filter and deep learning
How to talk about salary correctly in software testing interview
TCP聊天+传输文件服务器服务器套接字v2.8 - 修复已知程序4个问题
Redis系列——概述day1-1
Effects and laws
Protocol and hierarchy
Paper notes: lbcf: a large scale budget constrained causal forest algorithm
项目经理在项目中起到的作用
计网 | 形象理解路由协议RIP、OSPF、BGP
剑指 Offer II 025. 链表中的两数相加
App测试和Web测试的区别
浅谈 Web 3.0
[proficient in high concurrency] deeply understand the basis of C language and C language under assembly
TCP chat + transfer file server server socket v2.8 - fix 4 known problems
Sword finger offer II 025 Adding two numbers in a linked list
Internship: the annotation under swagger involves the provision of interfaces

![[untitled]](/img/14/ec21953b76a6a7bb1e692e08001571.png)







