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.
Try getting the width within the window onfocus event handler.
window.onfocus = function() { };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With