当前位置:网站首页>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();
})
- 需要查看如何自定义右键,可以查看我的文章 : 如何自定义右键
边栏推荐
猜你喜欢

PLSQL 存储函数SQL编程

Simple dialogue system -- implement transformer by yourself

2022-06-17 网工进阶(九)IS-IS-原理、NSAP、NET、区域划分、网络类型、开销值

「津津乐道播客」#386 原汤话原食:谁还不是个“白字先生”?

論文筆記:LBCF: A Large-Scale Budget-Constrained Causal Forest Algorithm

Involution? Foam? Change? Ten questions directly hit the core puzzle of "meta universe" – the essence of "ask ta- Wang Lei about the time of the universe"

万卷书 - 大力娃的书单

Redis系列——概述day1-1

Protocol and hierarchy

ddia数据密集型应用系统设计 整理
随机推荐
Ten thousand volumes - list of Dali wa
redis 分布式锁整理
【黑苹果】联想拯救者Y70002019PG0
The art of code annotation. Does excellent code really need no annotation?
How do components communicate
The role of the project manager in the project
数据搬迁最佳实践之使用CDM搬迁线下MySQL到DWS
微信公众号服务器配置
Involution? Foam? Change? Ten questions directly hit the core puzzle of "meta universe" – the essence of "ask ta- Wang Lei about the time of the universe"
Tasklet API usage
Wireshark网卡无法找到或没有显示的问题
SnakeYAML配置文件解析器
pychrm的这些配置,你都知道吗?
Do you know all the configurations of pychrm?
这些老系统代码,是猪写的么?
mood
从业一年,我是如何涨薪13K+?
论文笔记:Generalized Random Forests
Sword finger offer II 035 Minimum time difference
pytorch官方文档学习记录