How to get browser width using JavaScript code?

I am trying to write a JavaScript function to get the current browser width.

I found this one:

console.log(document.body.offsetWidth);

But its problem that it fail if the body has width 100%.

Is there any other better function or a workaround?

9 Answers
9

Leave a Comment