Window: resizeBy() 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.resizeBy()
method resizes the current windowby a specified amount.
Syntax
resizeBy(xDelta, yDelta)
Parameters
Return value
None (undefined
).
Examples
// Shrink the windowwindow.resizeBy(-200, -200);
Notes
This method resizes the window relative to its current size. To resize the window inabsolute terms, usewindow.resizeTo()
.
Creating and resizing an external window
For security reasons, it's no longer possible in Firefox for a website to change thedefault size of a window in a browser if the window wasn't created bywindow.open()
, or contains more than one tab. See the compatibility tablefor details on the change.
Even if you create window bywindow.open()
it is not resizable bydefault. To make the window resizable, you must open it with the"resizable"
feature.
// Create resizable windowmyExternalWindow = window.open( "https://example.com", "myWindowName", "resizable",);// Resize window to 500x500myExternalWindow.resizeTo(500, 500);// Make window relatively smaller to 400x400myExternalWindow.resizeBy(-100, -100);
The window you create must respect the Same Origin Policy. If the window you open isnot in the same origin as the current window, you will not be able to resize, or accessany information on, that window/tab.
Specifications
Specification |
---|
CSSOM View Module # dom-window-resizeby |
Browser compatibility
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.