+
95
-

回答

考虑到兼容,可以这样写

<script>
let rate = devicerate();
console.log("sr" + rate);
if(rate != 100){
alert('not 100% show');
}

function devicerate(){
var ratio = 0,
screen = window.screen,
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);
}

return ratio;
};
</script>


网友回复

我知道答案,我要回答