How to find the height and width of window WITHOUT JQUERY?

Asked

Viewed 949 times

5

I’ve been asking myself that for some time. I’ve tried somehow to figure out the size of window (browser window) but could not get it.

With jQuery I already know it’s just doing:

 $(window).height()

But, and in case I don’t have with jQuery, I don’t know how to do that.

Does anyone know how to get the height of the window (how to do with window in jQuery), but without jQuery?

  • 2

    In that reply here in OS have examples using javascript only.

  • @bfavaretto, it was bad. I had not seen this question at the time I wrote it

  • 2

    No problem, I think yours will be easier to find by Google

2 answers

7


You can use the window.inner...:

var w = window.innerWidth;
var h = window.innerHeight;
document.write(w + ' width ');
document.write(h + ' height');

  • 1

    Usa document.write to facilitate the snipet

  • 2

    @Wallacemaxters to be able to complete with Height or Width, dude there are things in js that are so simple that you think, why am I using jquery ?

  • The thing about jQuery is that you write less code and have greater compatibility with that code between browsers. Other than that, I think it’s important to know basic features like this. Imagine a test for programming, where you are without jQuery ?

  • 3

    @Wallacemaxters usually who does without jQuery, does with jQuery. The reverse does not. Probably a serious programming test would not even let use jQuery.

3

Get the size with toolbars/scrollbars

Reference : w3schools

var w = window.outerWidth;
var h = window.outerHeight;
 
document.write(w + ' width /' + h + ' height');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.