当前位置:网站首页>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();
})
- 需要查看如何自定义右键,可以查看我的文章 : 如何自定义右键
边栏推荐
- 论文笔记:LBCF: A Large-Scale Budget-Constrained Causal Forest Algorithm
- 单例模式应用
- pychrm的这些配置,你都知道吗?
- Sword finger offer II 012 The sum of left and right subarrays is equal
- 居家办公让我绩效拿了C | 社区征文
- Redis series - overview day1-1
- Solution to the problem of incorrect clock in FreeRTOS kernel
- Paper notes: lbcf: a large scale budget constrained causal forest algorithm
- Tasklet API usage
- The problem of missing precision of kettle table input components
猜你喜欢
巴比特 | 元宇宙每日荐读:三位手握“价值千万”藏品的玩家,揭秘数字藏品市场“三大套路”...
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"
Protocol and hierarchy
Are these old system codes written by pigs?
【微服务|Sentinel】流控规则概述|针对来源|流控模式详解<直接 关联 链路>
Ten thousand volumes - list of Dali wa
足下教育日精进自动提交
旧手机变废为宝,充当服务器使用
2022-06-17 advanced network engineering (x) is-is-general header, establishment of adjacency relationship, IIH message, DIS and pseudo node
SnakeYAML配置文件解析器
随机推荐
App测试工具大全,收藏这篇就够了
N皇后问题
Wireshark网卡无法找到或没有显示的问题
Knowing these interview skills will help you avoid detours in your test job search
Perfect shuffle problem
上线移动ERP系统有哪些步骤?环环紧扣很重要
万卷书 - 大力娃的书单
Sword finger offer II 025 Adding two numbers in a linked list
Why are there few embedded system designers in the soft test?
2022-06-17 网工进阶(十)IS-IS-通用报头、邻接关系的建立、IIH报文、DIS与伪节点
芝士糖豆打造AR潮玩新体验
1-8file sharing in VMWare
论文笔记:Generalized Random Forests
Ten thousand volumes - list of Dali wa
Generate post order traversal according to pre order traversal and mid order traversal
Uniapp to preview pictures (single / multiple)
tasklet api使用
JVM内存结构
vscode插件自用
Difference between app test and web test