Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect the viewport/window width with Modernizr?

I've found that using the Modernizr.mq() function to check media queries is a much more accurate way to run Javascript based on the viewport width, because it matches up with my CSS.

However, is it possible to get a width value from Modernizr?

like image 426
shrewdbeans Avatar asked Oct 27 '25 11:10

shrewdbeans


1 Answers

Using built-in tests, nope, that's not possible. At least, there are no mentions in the Modernizr docs.

However, you don't need Modernizr to get the dimensions of your browser. You can do it by using plain javascript:

var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;

Original answer

like image 190
gustavohenke Avatar answered Oct 29 '25 06:10

gustavohenke