EN
本內容沒有您的語言版本,但有英文版本。

logicalXDPI property

Gets the normal number of horizontal dots per inch (DPI) of the system's screen.

Syntax

JavaScript

p = object.logicalXDPI

 

Property values

Type: Integer

the DPI.

Standards information

There are no standards that apply here.

Remarks

On most systems, there is no difference between horizontal and vertical DPI. The normal DPI on most Windows systems is 96.

When Windows Internet Explorer is adjusting the scale of the screen, the value of this property does not equal the value of the deviceXDPI property.

logicalXDPI was introduced in Microsoft Internet Explorer 6.

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 logicalXDPI property to retrieve the normal 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 -ms-zoom property of the BODY element to adjust the scale of the document "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>

See also

screen
Reference
devicePixelRatio
deviceXDPI
deviceYDPI
logicalYDPI

 

 

顯示:
© 2014 Microsoft