Scaling here refers not to the size of the browser, but to the percentage of the content of the browser's Web page (press CTRL and + key or-the zoom of the number key).
There is a way to detect this scaling, QQ space all through flash to detect whether the browser is in the zoom. This provides a JavaScript way to detect browser scaling.
For IE6, it is simply ignored because IE6 can only scale the text.
First of all, the browser provides a standard instrumentation interface, Window.devicepixelratio is the device on the physical pixel and device independent pixel ratio, this property can be used to detect whether the Web page has been scaled. On a normal PC browser, the default value of 1 is the default without scaling. At present, Firefox, Chrome and so on have been very good support.
OK, then let's talk about IE's processing methods. IE provides Window.screen.deviceXDPI and Window.screen.logicalXDPI two attributes, devicexdpi is the physical pixel on the corresponding device, and logicalxdpi is the ratio of independent pixels of the device. The estimated standard detection interface is also only an improvement based on the IE method. The default values for these two properties on systems above Windows xp+ are 96, because the system defaults to 96dpi.
For browsers that are not supported by either of these two properties, you can also take advantage of both Window.outerwidth and window.innerwidth. Outerwidth returns the external actual width of the window element, Innerwidth returns the internal actual width of the window element, which contains the width of the scroll bar.
With these attributes, you can basically handle the browsers that are common on PC browsers. The implementation code is as follows:
The return value of the Detectzoom function, if 100 is the default zoom level, greater than 100 is magnified, and less than 100 is reduced.
function Detectzoom () {
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/wi ndow.innerwidth;
}
if (ratio) {
ratio = Math.Round (ratio *);
}
return ratio;
};
original articles, reproduced please specify: reprinted from the front-end development