Disable Chrome pinch zoom for use in kiosk

前端 未结 6 2068

We are using Chrome in kiosk mode and accidentally users are causing the application to zoom with the recent addition of pinch zoom support. They then think they\'ve broken it

6条回答
  •  醉酒成梦
    2021-01-30 11:11

    Another solution that currently works in Chrome (54) is to add an event listener for the 'touchstart' event and call preventDefault() based on the length of the targetTouches or touches on the event.

    This solution prevents a pinch (any two fingered gesture for that matter), but still provides flexibility with how you want to respond to the event. It's a nice solution because it doesn't require you to disable touch events altogether (as required if you want to disable pinch using the chrome flags, since chrome://flags/#enable-pinch no longer exists).

    window.addEventListener('touchstart', function(e) {
      if (e.targetTouches.length === 2) {
        e.preventDefault();
      }
    }, false);
    Some text that you can't pinch zoom on Chrome (tested in 54)

提交回复
热议问题