Window: resizeTo() method
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheWindow.resizeTo()
method dynamically resizes thewindow.
Syntax
resizeTo(width, height)
Parameters
width
An integer representing the new
outerWidth
inpixels (including scroll bars, title bars, etc.).height
An integer value representing the new
outerHeight
in pixels (including scroll bars,title bars, etc.).
Return value
None (undefined
).
Examples
This function resizes the window so that it takes up one quarter of the availablescreen. See theScreen.availWidth
andScreen.availHeight
properties.
function quarter() { window.resizeTo(window.screen.availWidth / 2, window.screen.availHeight / 2);}
Specifications
Specification |
---|
CSSOM View Module # dom-window-resizeto |
Browser compatibility
Note: It's not possible to resize a window or tab that wasn't created bywindow.open()
. It's also not possible to resize when thewindow has multiple tabs.
Note:This function might not resize the window synchronously.In some environments (like mobile) it might not resize the window at all. Youcan listen to theresize
event to seeif/when the window got resized.