W3cubDocs

/DOM

window.resizeBy

Resizes the current window by a certain amount.

Syntax

window.resizeBy(xDelta, yDelta) 

Parameters

  • xDelta is the number of pixels to grow the window horizontally.
  • yDelta is the number of pixels to grow the window vertically.

Example

// shrink the window 
window.resizeBy(-200, -200);

Notes

This method resizes the window relative to its current size. To resize the window in absolute terms, use window.resizeTo.

For security reasons, it's no longer possible for a web site to change the default size of a window in a browser if the window wasn’t created by window.open or contains more than one tab. See the compatability table for details on the change.

Also, even if you create window by window.open(...) it is not resizable by default. To make window created by window.open() resizable, you must open it with resizable feature.

Creating and resizing an external window with "resizable" feature

myExternalWindow = window.open("http://myurl.domain", "myWindowName", "resizable");
myExternalWindow.resizeTo(500,500); //resize window to 500x500
myExternalWindow.resizeBy(-100,-100); //make it smaller relatively => to 400x4

The window you create must respect the Same Origin Policy. If the window you open is not in the same orgin as the current window, you will not be able to resize, or access any information on, that window/tab.

Specifications

Browser CompatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes ? Yes
Yes
Since Firefox 7, it's no longer possible for a web site to change the default size of a window in a browser if the window wasn’t created by window.open or contains more than one tab. See here for more details.
? ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes ? Yes ? ? ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/resizeBy