How to detect page zoom level in all modern browsers?

后端 未结 28 1823
慢半拍i
慢半拍i 2020-11-21 05:27
  1. How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can\'t find a good cross-browser solution.

28条回答
  •  醉酒成梦
    2020-11-21 06:02

    On mobile devices (with Chrome for Android or Opera Mobile) you can detect zoom by window.visualViewport.scale. https://developer.mozilla.org/en-US/docs/Web/API/Visual_Viewport_API

    Detect on Safari: document.documentElement.clientWidth / window.innerWidth (return 1 if no zooming on device).

提交回复
热议问题