javascript 使用javascript检测浏览器缩放级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4130649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect Browser zoom level using javascript
提问by Sakeer
Is it possible to detect the browser zoom level when the user changed the zoom level of browser, and the default zoom level using javascript. I need to call different xml files according to the zoom level change.
是否可以在用户更改浏览器缩放级别时检测浏览器缩放级别,以及使用 javascript 的默认缩放级别。我需要根据缩放级别的变化调用不同的 xml 文件。
回答by tom
I found that you have to vary for each browser:
我发现每个浏览器都必须有所不同:
This works great in safari and chrome:
这在 safari 和 chrome 中非常有效:
zoom = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width,10)/document.documentElement.clientWidth
This works well in IE8+ (unless your user has some freakish screen....):
这在 IE8+ 中运行良好(除非您的用户有一些奇怪的屏幕......):
zoom = window.screen.deviceXDPI/96
And for Firefox and IE7 I use thisalthough I still haven't got it to work with Firefox on the Mac...
对于 Firefox 和 IE7,我使用它,尽管我还没有让它在 Mac 上与 Firefox 一起使用......
Good luck.
祝你好运。

