Prevent the browser from zooming the page

pc side

Only the zoom-in and zoom-out behavior of the browser shortcut keys can be disabled, and the zoom-in and zoom-out behavior of the computer itself belongs to the system authority

  • ctrl + +/-
  • ctrl + scroll wheel
  • cammond + +/-

code show as below:

// 禁止通过	ctrl + +/- 和 	ctrl + 滚轮 对页面进行缩放
  document.addEventListener('keydown', function (event) {
    
    
    if ((event.ctrlKey === true || event.metaKey === true) &&
      (event.which === 61 || event.which === 107 ||
        event.which === 173 || event.which === 109 ||
        event.which === 187 || event.which === 189)) {
    
    
      event.preventDefault()
    }
  }, false)
  // Chrome IE 360
  window.addEventListener('mousewheel', function (event) {
    
    
    if (event.ctrlKey === true || event.metaKey) {
    
    
      event.preventDefault()
    }
  }, {
    
    
    passive: false
  })

  // firefox
  window.addEventListener('DOMMouseScroll', function (event) {
    
    
    if (event.ctrlKey === true || event.metaKey) {
    
    
      event.preventDefault()
    }
  }, {
    
    
    passive: false
  })

mobile terminal

Just add it to the tag. code show as below:

<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">

Guess you like

Origin blog.csdn.net/pink_cz/article/details/128085810