0

I would like to find the innerWidth and innerHeight of the screen via Javascript, and then place the values into the width and height variables of the body class in the style area (css) of HTML. For example:

<style>
  body { background-image: url("images/hello.jpg"); 
         background-repeat: no-repeat; background-color: brown; 
         width: valueW; height: valueH;}
</style>

Where valueW is the returned value of the pixels of the innerWidth of the screen, and valueH for innerHeight. The "px" pixels value would need to follow the returned number of course.

Is this possible?

Thanks for any input.

guardabrazo
  • 1,219
  • 1
  • 13
  • 26
  • 1
    Have you read [this question?](http://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window) – Mike Cluck Sep 12 '16 at 21:26
  • Why do you need this? Using fixed positioning may be an easier solution for what you need. – Jacob Sep 12 '16 at 21:26

1 Answers1

2

You're looking for the CSS vh and vw units, which do that automatically.
No Javascript needed.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964