HTML 页面禁止缩放功能

页面禁止缩放

代码如下:

js 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0,  user-scalable=no;">
    <meta name="theme-color" content="#000000">
    <title>页面禁止缩放功能</title>
  </head>
  <!-- 禁止鼠标右键 oncontextmenu="return false"-->
  <body oncontextmenu="return false">
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <script>
    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 });
    // 触摸屏禁止手动缩放页面
    document.documentElement.addEventListener('touchstart', (event) => {
      if(event.touches.length > 1) {
        event.preventDefault();
      }
    },{
      passive: false
    }) 
    </script>
  </body>
</html>
相关推荐
❀͜͡傀儡师2 分钟前
docker部署Docker Compose文件Web管理工具Dockman
java·前端·docker·dockman
karshey18 分钟前
【前端】sort:js按照固定顺序排序
开发语言·前端·javascript
MyBFuture19 分钟前
索引器实战:对象数组访问技巧及命名空间以及项目文件规范
开发语言·前端·c#·visual studio
IT_陈寒29 分钟前
Redis性能提升50%的7个实战技巧,连官方文档都没讲全!
前端·人工智能·后端
打小就很皮...31 分钟前
React 富文本图片上传 OSS 并防止 Base64 图片粘贴
前端·react.js·base64·oss
咬人喵喵38 分钟前
告别无脑 <div>:HTML 语义化标签入门
前端·css·编辑器·html·svg
404NotFound3051 小时前
基于 Vue 3 和 Guacamole 搭建远程桌面(利用RDP去实现,去除vnc繁琐配置)
前端
咚咚咚ddd1 小时前
AI 应用开发:Agent @在线文档功能 - 前端交互与设计
前端·aigc·agent
旧梦吟1 小时前
脚本工具 批量md转html
前端·python·html5