How to detect page zoom level in all modern browsers?

后端 未结 28 1883
慢半拍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 05:53

    In Internet Explorer 7, 8 & 9, this works:

    function getZoom() {
        var screen;
    
        screen = document.frames.screen;
        return ((screen.deviceXDPI / screen.systemXDPI) * 100 + 0.9).toFixed();
    }
    

    The "+0.9" is added to prevent rounding errors (otherwise, you would get 104% and 109% when the browser zoom is set to 105% and 110% respectively).

    In IE6 zoom doesn't exists, so it is unnecessary to check the zoom.

提交回复
热议问题