5

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

Thanks

thomas-hiron
  • 918
  • 4
  • 20
  • 40

4 Answers4

11

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

Christian
  • 19,349
  • 3
  • 53
  • 70
6

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
BenM
  • 51,470
  • 24
  • 115
  • 164
1

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

width: device-width;
asgoth
  • 34,968
  • 12
  • 88
  • 97
1

You should use:

window.screen.availHeight
window.screen.availWidth
ATOzTOA
  • 32,738
  • 21
  • 92
  • 115