thomas-hiron
thomas-hiron

Reputation: 948

Get native screen resolution using jQuery

I'd like to get the native screen width on a device to append scripts in the DOM. Is it possible using jQuery ?

Thanks

Upvotes: 5

Views: 33240

Answers (4)

ATOzTOA
ATOzTOA

Reputation: 35950

You should use:

window.screen.availHeight
window.screen.availWidth

Upvotes: 1

BenM
BenM

Reputation: 53208

Sure. You can get the basic width and height using:

screen.width;
screen.height;

If required, you can also get the pixel ratio (useful if you need to also detect retina displays) by using:

window.devicePixelRatio

Upvotes: 6

asgoth
asgoth

Reputation: 35829

You can set the width to device width with a css property:

width: device-width;

Upvotes: 1

Christian
Christian

Reputation: 19750

window.screen.width? Source: https://developer.mozilla.org/en-US/docs/DOM/window.screen

Upvotes: 12

Related Questions