4

I want to get the display dimensions of my monitor.

Is it possible to do with JavaScript or Flash?

I tried the following function:

var dpi_x = document.getElementById('testdiv').offsetWidth;
        var dpi_y = document.getElementById('testdiv').offsetHeight;
        var width_in = screen.width / dpi_x;
        var height_in = screen.height / dpi_y;
        var diagonal_in = Math.round(10 * Math.sqrt(width_in * width_in + height_in * height_in)) / 10;

but it doesn't show the fixed diagonal value... because when I change the resolution of the display...

Where as I want the fixed dimension like 16.5"... I mean, it should be fixed for any specific monitor..

Mörre
  • 5,699
  • 6
  • 38
  • 63
Ravi Tuvar
  • 191
  • 1
  • 2
  • 14
  • i dont want it based on screen resolution..cause when i change the resolution it varies.. – Ravi Tuvar Aug 21 '12 at 08:40
  • I'm not sure this is possible, at all. And why you want to detect the physical dimensions, rather than the resolution? A monitor that's x inches diagonally might be set to one of multiple resolutions. – Jack Franklin Aug 21 '12 at 08:42
  • 1
    Hi Jack..thanks for your reply..but i need it to set my video object size based on the Diagonally..because we are in streaming application development and want to show the streaming on any device like mobile, desktop, laptop, Smart TV etc.. so in a way i need to know the size of the device..! – Ravi Tuvar Aug 21 '12 at 08:46
  • @RaviTuvar, is your `
    ` styled to be one inch high?
    – Simon MᶜKenzie Aug 22 '12 at 06:44
  • 1
    @SimonMcKenzie yes it is like this..
    – Ravi Tuvar Aug 23 '12 at 08:55
  • 1
    @RaviTuvar, so what happens in your code? It looks correct to me, assuming your browser is accurately rendering your one-inch high div (which of course depends on the OS, the browser, and whether the screen accurately reports its DPI/dimensions to the OS) - does is look like it's 1" tall? – Simon MᶜKenzie Aug 23 '12 at 09:11

1 Answers1

4

It's not possible to detect the physical dimensions. Resolution is as close as you're gonna get.

Asciiom
  • 9,867
  • 7
  • 38
  • 57