使用javascript检测浏览器缩放级别

编程入门 行业动态 更新时间:2024-10-28 14:35:01
本文介绍了使用javascript检测浏览器缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当用户使用javascript更改浏览器的缩放级别和默认缩放级别时,可以检测浏览器缩放级别。我需要根据缩放级别更改调用不同的xml文件。

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.

推荐答案

我发现你必须为每个浏览器:

I found that you have to vary for each browser:

这在safari和chrome中效果非常好:

This works great in safari and chrome:

zoom = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width,10)/document.documentElement.clientWidth

这在IE8 +(除非你的用户有一些奇怪的屏幕....):

This works well in IE8+ (unless your user has some freakish screen....):

zoom = window.screen.deviceXDPI/96

对于Firefox和IE7,我使用这 虽然我还没有它可以在Mac上使用Firefox ...

And for Firefox and IE7 I use this although I still haven't got it to work with Firefox on the Mac...

祝你好运。

更多推荐

使用javascript检测浏览器缩放级别

本文发布于:2023-11-09 16:15:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   浏览器   级别   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!