Get Device Screen Size in Cordova/PhoneGap App

| | 1 min read

Identifying size of device screen is easy in a Cordova application. But is not available directly. We can get the screen object from window.screen and it has width and height properties. The problem is, these width and height may not represent physical screen, but the concept called CSS pixel.

Fortunately there is property window.devicePixelRatio which keep the ratio from physical pixels to CSS pixels. We can use this value to get physical screen size as given below.


var physicalScreenWidth = window.screen.width * window.devicePixelRatio;
var physicalScreenHeight = window.screen.height * window.devicePixelRatio;

Please note that the value will change depending on current orientation of screen.

Hope the above helps. Please feel free to get in touch to know more.