cbdeveloper
cbdeveloper

Reputation: 31365

Shouldn't window.screenX and window.screenY work on browsers on mobile devices?

When I log window.screenX on my desktop Chrome, I see the value 1920

When I do the same on my phone and iPad both on Safari and Mobile I either see 0 or some really weird values.

From MDN Link:

enter image description here

QUESTION

Isn't that supposed to work on both desktop and mobile, devices and browsers?

Upvotes: 2

Views: 1507

Answers (1)

Stephen M Irving
Stephen M Irving

Reputation: 1512

What information are you actually trying to return? From your MDN link:

Returns:

A number equal to the number of CSS pixels from the left edge of the browser viewport to the left edge of the screen.

Do you have your browser in a windowed mode on your mobile devices? Because in a full screen mode, like most mobile device browsers remain in, it should always return 0 because there are no pixels between the left hand side of the device's screen and the start of the browser window.

Are you actually trying to measure the space between the left side of the screen and the start of the browser viewport, or are you really trying to get the horizontal resolution of the entire screen? If it is the latter, what you are looking for may be the window.screen.width property. The documentation for that property can be found here on MDN.

Upvotes: 2

Related Questions