Is it possible, to do with javascript an 'if device-width' or something like that?

if that would be possible can i do something like this:

if device-width="100px" {} else {}

Thanks.

2 answers

0
points

Have you tried screen.width?

Answered over 6 years ago by Nathan Duran
  • no, i really need device-width kind, otherwise it would be to easy to fake, right? TutorialPoint over 6 years ago
  • If a browser fakes a screen width then it might fake everything, so I wouldn't really be particularly concerned about that unless you have a concrete instance where that is known to be an issue. Nathan Duran over 6 years ago
Mottie 1134
0
points

You could try screen.availWidth (ref)... I'm not sure what you mean by faking the width.

If you are designing something for a small screen (e.g. an iPhone), then try using CSS:

<link media="only screen and (max-device-width: 480px)" href="iPhone.css" type="text/css" rel="stylesheet" />

or target it inside your CSS:

@media only screen and (max-device-width:480px) {
 /* add specific CSS here */
}
Answered over 6 years ago by Mottie
  • If you added a specific style to an off screen element inside the stylesheet you could then use getComputedStyle as a fairly straightforward test? Rob Crowther over 6 years ago