1

I was using javascript to obtain the my display resolution. The following code gave me the result of 1440 x 900 for my Macbook Pro

var screenWidth = screen.width;
var screenHeight = screen.height;

However, when I go check display setting of my Mac. It shows 2880 x 1800. I'm wondering if I was on the wrong track on getting the resolution of a display?

Macbook Pro display setting

0

1 Answer 1

5

You have a Retina display. You can use devicePixelRatio to determine what the physical display size is.

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

In your example, devicePixelRatio will be 2

Sign up to request clarification or add additional context in comments.

3 Comments

It works great for me. But just have a question, is that gonna work on all devices through different browsers?
This does not work on Chrome if you have the page zoomed in or out, with Ctrl+ or Ctrl-

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.