Browser zoom detection js code
- 2020-03-30 04:04:35
- OfStack
The test code
(link: http://jsbin.com/dipijeqi/11)
Effect:
chrome
window.devicePixelRatio : 2 ( accurate )
screen.deviceXDPI / screen.logicalXDPI : NaN
window.outerWidth / window.innerWidth : 2
document.documentElement.offsetHeight / window.innerHeight : 0.020618556701030927 ( There are correlations )
window.top.outerWidth / window.top.innerWidth : 2
ff
window.devicePixelRatio : 1.5 ( accurate )
screen.deviceXDPI / screen.logicalXDPI : NaN
window.outerWidth / window.innerWidth : 1.0114583333333333
document.documentElement.offsetHeight / window.innerHeight : 0.023391812865497075 ( There are correlations )
window.top.outerWidth / window.top.innerWidth : 1.0114583333333333
Ie 8
window.devicePixelRatio : undefined
screen.deviceXDPI / screen.logicalXDPI : 1.5416666666666667 ( Roughly accurate )
window.outerWidth / window.innerWidth : NaN
document.documentElement.offsetHeight / window.innerHeight : NaN
window.top.outerWidth / window.top.innerWidth : NaN
ie11
window.devicePixelRatio : 1.5 ( accurate )
screen.deviceXDPI / screen.logicalXDPI : 1.5
window.outerWidth / window.innerWidth : 1.0084033613445377
document.documentElement.offsetHeight / window.innerHeight : 0.02203856749311295 ( There are correlations )
window.top.outerWidth / window.top.innerWidth : 1.0084033613445377
build
window.devicePixelRatio : undefined
screen.deviceXDPI / screen.logicalXDPI : 1.5 ( accurate )
window.outerWidth / window.innerWidth : 1.0084033613445377
document.documentElement.offsetHeight / window.innerHeight : 1
window.top.outerWidth / window.top.innerWidth : 1.0084033613445377
Internet explorer 9
The same code at the page code block index 4
360 6.3(no reaction at all)
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 extreme speed browser
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( accurate )
Sogou high speed browser (no response at all)
The same code at the page code block index 6
Taobao browser
window.devicePixelRatio : 1
screen.deviceXDPI / screen.logicalXDPI : NaN
window.outerWidth / window.innerWidth : 2.0710059171597632 ( Roughly accurate )
document.documentElement.offsetHeight / window.innerHeight : 0.022988505747126436
window.top.outerWidth / window.top.innerWidth : 2.0710059171597632