Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not understand result from $(window).width()

I have several pages and I notice one strange moment, this code:

var w = $(window).width();
alert(w);
  • sometimes returns result: 1440, (and this is true, my screen resolution is 1440 x 900)
  • sometimes (in different pages) returns: 1423.

From whence this result, I dont understood.

$(window).width() must be always (from all pages) return the same result, mustn't it?

like image 619
Oto Shavadze Avatar asked Dec 12 '25 17:12

Oto Shavadze


2 Answers

The scrollbar is not included. From your results, 1440 - 1423 = 17px, which is the same width as my scrollbar (e.g. here on Stack Overflow).

like image 153
pimvdb Avatar answered Dec 15 '25 15:12

pimvdb


It returns 1423 when you have the scrollbar visible.

The width returned when the scrollbar is visible might change on different browsers and operating systems.

like image 37
gabitzish Avatar answered Dec 15 '25 17:12

gabitzish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!