获取浏览器页面缩放或展示比例
翻页面的时候,不经意看到了 ****还是什么页面 给提示‘您当前页面处于缩放,页面可能会错乱’;就好奇 怎么获取到 页面是否缩放和 缩放比例的,所以就查询了一下:得到了 下面的结果 做个记录;
原文地址:https://www.cnblogs.com/dyhao/p/11458882.html
var ratio=0;
var screen=window.screen;
var ua=navigator.userAgent.toLowerCase();
if(window.devicePixelRatio !== undefined)
{
ratio=window.devicePixelRatio;
}
else if(~ua.indexOf('msie'))
{
if(screen.deviceXDPI && screen.logicalXDPI)
{
ratio=screen.deviceXDPI/screen.logicalXDPI;
}
}
else if(window.outerWidth !== undefined && window.innerWidth !== undefined)
{
ratio=window.outerWidth/window.innerWidth;
}
if(ratio)
{
ratio=Math.round(ratio*100);
}
控制台执行 代码后验证 还是很准确的;所以笔记 记录和分享一下;