Newbie
Newbie

Reputation: 373

Javscript - How can I determine physical screen width and height

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

Upvotes: 0

Views: 1483

Answers (2)

Asad Gulzar
Asad Gulzar

Reputation: 672

Use

window.height and window.width

Upvotes: -1

Ashwin Agarwal
Ashwin Agarwal

Reputation: 81

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.

Upvotes: 2

Related Questions