Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.outerWidth equals 0 when out of focus tab

I am using window.outerWidth to get the width of the window which works fine. The problem is however that window.outerWidth will be 0 if you load the page in a tab that is not in focus. Is there any workaround for this?

The same behavior is on Chrome and Firefox.

Solution: I decided to use window.innerWidth instead since it gives the correct width even when the tab is out of focus and gave the same desired results in my case.

like image 955
Kos Cos Avatar asked Nov 16 '22 04:11

Kos Cos


1 Answers

Try getting the width within the window onfocus event handler.

window.onfocus = function() { };
like image 80
Eric Svitok Avatar answered Mar 06 '23 18:03

Eric Svitok