浏览器缩放检测的js代码


Posted in Javascript onSeptember 28, 2014

测试代码

http://jsbin.com/dipijeqi/11

效果:

chrome

window.devicePixelRatio : 2  (准确)

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 2

document.documentElement.offsetHeight / window.innerHeight : 0.020618556701030927 (有相关性)

window.top.outerWidth / window.top.innerWidth : 2

ff

window.devicePixelRatio : 1.5 (准确)

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 1.0114583333333333

document.documentElement.offsetHeight / window.innerHeight : 0.023391812865497075  (有相关性)

window.top.outerWidth / window.top.innerWidth : 1.0114583333333333

ie 8

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5416666666666667 (大致准确)

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

ie11

window.devicePixelRatio : 1.5 (准确)

screen.deviceXDPI / screen.logicalXDPI : 1.5

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 0.02203856749311295 (有相关性)

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

ie10

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确)

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 1

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

ie9

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确)

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 1

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

360 6.3(完全没反应)

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

360极速浏览器

window.devicePixelRatio : 1

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 1.5

document.documentElement.offsetHeight / window.innerHeight : 0.015267175572519083

window.top.outerWidth / window.top.innerWidth : 1.5(准确)

搜狗高速浏览器 (完全没反应)

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

淘宝浏览器

window.devicePixelRatio : 1

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 2.0710059171597632  (大致准确)

document.documentElement.offsetHeight / window.innerHeight : 0.022988505747126436

window.top.outerWidth / window.top.innerWidth : 2.0710059171597632
Javascript 相关文章推荐
使用javascript实现页面定时跳转总结篇
Sep 21 Javascript
js的for in循环和java里foreach循环的区别分析
Jan 28 Javascript
jquery实现炫酷的叠加层自动切换特效
Feb 01 Javascript
jquery 删除节点 添加节点 找兄弟节点的简单实现
Dec 07 Javascript
jquery实现的table排序功能示例
Mar 10 Javascript
jQuery正则验证注册页面经典实例
Jun 10 jQuery
JS获取数组中出现次数最多及第二多元素的方法
Oct 27 Javascript
如何在wxml中直接写js代码(wxs)
Nov 14 Javascript
微信小程序封装多张图片上传api代码实例
Dec 30 Javascript
微信小程序保存图片到相册权限设置
Apr 09 Javascript
浅析JavaScript 函数防抖和节流
Jul 13 Javascript
js用正则表达式筛选年月日的实例方法
Jan 04 Javascript
排序算法的javascript实现与讲解(99js手记)
Sep 28 #Javascript
Javascript中封装window.open解决不兼容问题
Sep 28 #Javascript
jQuery固定浮动侧边栏实现思路及代码
Sep 28 #Javascript
js文件包含的几种方式介绍
Sep 28 #Javascript
javascript中bind函数的作用实例介绍
Sep 28 #Javascript
js和jquery如何获取图片真实的宽度和高度
Sep 28 #Javascript
一个jquery实现的不错的多行文字图片滚动效果
Sep 28 #Javascript
You might like
PHP+iFrame实现页面无需刷新的异步文件上传
2014/09/16 PHP
php中unserialize返回false的解决方法
2014/09/22 PHP
9段PHP实用功能的代码推荐
2014/10/14 PHP
详解php中反射的应用
2016/03/15 PHP
PHP模板引擎Smarty内建函数section,sectionelse用法详解
2016/04/11 PHP
php ucwords() 函数将字符串中每个单词的首字符转换为大写(实现代码)
2016/05/12 PHP
thinkPHP中配置的读取与C方法详解
2016/12/05 PHP
可缩放Reloaded-一个针对可缩放元素的复用组件
2007/03/10 Javascript
js字符串的各种格式的转换 ToString,Format
2011/08/08 Javascript
jQuery中;function($,undefined) 前面的分号的用处
2014/12/17 Javascript
JS制作简单的三级联动
2015/03/18 Javascript
JS创建对象几种不同方法详解
2016/03/01 Javascript
JS表格组件BootstrapTable行内编辑解决方案x-editable
2016/09/01 Javascript
Bootstrap如何激活导航状态
2017/03/22 Javascript
详解Javascript获取缓存和清除缓存API
2017/05/25 Javascript
validationEngine 表单验证插件使用实例代码
2017/06/15 Javascript
纯js实现页面返回顶部的动画(超简单)
2017/08/10 Javascript
详解js模板引擎art template数组渲染的方法
2018/10/09 Javascript
Vue使用localStorage存储数据的方法
2019/05/27 Javascript
JS实现小星星特效
2019/12/24 Javascript
[03:57]2016完美“圣”典风云人物:rOtk专访
2016/12/09 DOTA
详解Python中__str__和__repr__方法的区别
2015/04/17 Python
Python实现八大排序算法
2016/08/13 Python
pytorch torch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解
2020/01/03 Python
Python -m参数原理及使用方法解析
2020/08/21 Python
Python模拟登录requests.Session应用详解
2020/11/17 Python
瑞典度假品牌:OAS
2019/05/28 全球购物
初入社会应届生求职信
2013/11/18 职场文书
幼儿园教师师德师风演讲稿:爱我所爱 无悔青春
2014/09/10 职场文书
正风肃纪剖析材料
2014/09/30 职场文书
婚礼新人答谢词
2015/01/04 职场文书
证劵公司反洗钱宣传活动总结
2015/05/08 职场文书
记者节感言
2015/08/03 职场文书
2016年重阳节慰问信
2015/12/01 职场文书
初中生入团申请书范文(五篇)
2019/10/16 职场文书
oracle DGMGRL ORA-16603报错的解决方法(DG Broker)
2021/04/06 Oracle