HBCMS更多的中文手册参考:

deviceXDPI Property

DHTML文档教程

Retrieves the actual number of horizontal dots per inch (DPI) of the system's screen.

dhtml语法

[ nActDPI = ] screen.deviceXDPI

DHTML可能的值

nActDPIInteger that receives the DPI.

The property is read-only. The property has no default value.

Remarks

On most systems, there is no difference between horizontal and vertical DPI.

For information about how Internet Explorer 6 and later can adjust the scale of the display on screens with higher-than-normal DPI, see adjusting scale for higher dpi screens.

Examples

The following examples use the deviceXDPI property to retrieve the horizontal DPI of the screen.

This example uses the deviceXDPI and logicalxdpi properties to calculate the horizontal scale factor that internet explorer is applying. the function in this example returns 1 if internet explorer is not adjusting the scale of the screen.

<script>
function fnScaleFactorX() {
var nScaleFactor = screen.deviceXDPI / screen.logicalXDPI;
return nScaleFactor;
}
</script>

This example uses the zoom property of the body element to adjust the scale of the page "manually" if internet explorer is not adjusting the scale of the screen and the user's horizontal dpi is higher than normal. this is a simple but imprecise way to make a document look the same on higher resolution screens. you can achieve finer control over the layout of your documents by modifying the properties of individual elements or groups of elements.

<script>
// change layout on HighDPI screens when IE not scaling
function fnScaleManually()
{
// normal DPI
var constNorm = 96;
// scaling is off and DPI higher than normal
if ((screen.deviceXDPI == screen.logicalXDPI)
&& (screen.deviceXDPI > constNorm))
{
document.body.style.zoom =
constNorm / screen.logicalXDPI;
}
}
</script>

Applies To

screen

更多语法参考

deviceydpi, logicalxdpi, logicalYDPI