0

What I want I want to know physical screen width and height using javscript

Why I want I want it so that I can use it when a portrait screen device(like mobile phone) wants to have a video call with landscape device(like laptop). This way I can swap width and height constraints according to the other end of the call. So for mobile device I will send video in portrait mode and for laptop I will send it in landscape mode, by swapping width and height dimensions(constraints).

I would like to know a device original screen size or orientation irrespective of browser widow size change or device is orientation change.

I have already found many posts asking about orientation or dimensions but they all seem to have some flaws, according to the comments, and some don't address physical screen dimensions.

I have mentioned what I aim to achieve. Maybe there is a better way to achieve that.

Please help.

Thank you

Newbie
  • 343
  • 2
  • 13
  • Does this answer your question? [Getting the physical screen dimensions / dpi / pixel density in Chrome on Android](https://stackoverflow.com/questions/21680629/getting-the-physical-screen-dimensions-dpi-pixel-density-in-chrome-on-androi) This applies to all devices in my knowledge – Ayushya Dec 06 '20 at 06:25
  • but for your specific task , i prefer the window height & width . Because , even if a person is using laptop , his browser may not always be full size. Check out media queries in css for giving different styles for different width and height – Sandrin Joy Dec 06 '20 at 07:29
  • Also , changing the video aspect ratio , will drastically reduce the quality of the video & stretches' also might happen. – Sandrin Joy Dec 06 '20 at 08:00

2 Answers2

2

You could use screen.height and screen.width properties in javascript to get the height and width of the user's screen in pixels (irrespective of the browser size).

> screen.width
2048
> screen.height
1280

This works with most browsers and certainly works with Chrome, IE, Safari, Firefox, Opera.

0

Use

window.height and window.width
Asad Gulzar
  • 403
  • 4
  • 8