Gets the browser page zoom ratio or display

Turn the page when inadvertently see csdn or what page to a prompt 'your current page in zoom, the page may be confused'; it is curious how get to the page whether to scale and scale, so we inquired about: get the following The results to be recorded;

 

Original Address: 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);    
    }

 

The console is still very accurate verification of the implementation of the code; so note-taking and share;

Published 301 original articles · 197 won praise · views 270 000 +

Guess you like

Origin blog.csdn.net/boss_way/article/details/103033895