How to detect page zoom level in all modern browsers?

后端 未结 28 2221
慢半拍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:59

    You can try

    var browserZoomLevel = Math.round(window.devicePixelRatio * 100);
    

    This will give you browser zoom percentage level on non-retina displays. For high DPI/retina displays, it would yield different values (e.g., 200 for Chrome and Safari, 140 for Firefox).

    To catch zoom event you can use

    $(window).resize(function() { 
    // your code 
    });
    

提交回复
热议问题