Reputation: 20468
What is the difference between screen.width
and screen.availwidth
in JavaScript?
On my system both are the same!
Upvotes: 21
Views: 21010
Reputation: 861
An example might help understand the difference between:
screen.width and screen.availWidth
screen.height and screen.availHeight
In Windows XP/7/ecc. there is a thing called taskbar.
The taskbar is where the start button/clock etc. are.
The taskbar is usually at the bottom of the screen.
Case 1
Our browser is maximized, we can see the Windows taskbar under the browser.
window.outerHeight == screen.availHeight == all the height minus the taskbar
Case 2
Our browser is fullscreen (usually clicking F11), we can't see the Windows taskbar.
window.outerHeight == screen.height == all the height
For screen.width and screen.availWidth the reasoning is the same.
Upvotes: 1
Reputation: 2878
window.screen.width
-> Returns the width of the screen.
window.screen.availWidth
-> Returns the amount of horizontal space in pixels available to the window.
It is best to use screen.availWidth
for the exact size available for our component example.
Upvotes: 9
Reputation: 490233
Some things block some of your viewport, such a history/bookmarks side panel. This includes the taskbar, unless it's on Autohide
Then window.screen.width != window.screen.availWidth
. :)
If you are drawing things to the viewport, you ought to use availWidth
/ availHeight
to determine if things are off the viewport etc. Be sure to recalculate on window resize otherwise you won't know when the sidepanel has been closed.
Note that not all of the width given by this property may be available to the window itself. When other widgets occupy space that cannot be used by the window object, there is a difference in window.screen.width and window.screen.availWidth.
Upvotes: 24