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
  • 928
  • 4
  • 21
  • 40

4 Answers4

12

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

Christian
  • 19,605
  • 3
  • 54
  • 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
  • 52,573
  • 26
  • 113
  • 168
1

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

width: device-width;
asgoth
  • 35,552
  • 12
  • 89
  • 98
1

You should use:

window.screen.availHeight
window.screen.availWidth
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117