Javascript Browser Window resizeTo() Method

Introduction

Open a new window, and set its width and height to 250px:

Open a new window, and resize the width and height to 500px:

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="openWin()">Create window</button>
<button onclick="resizeWin()">Resize window</button>

<script>
var myWindow;/* w w  w  .ja  v a2 s. c  o m*/

function openWin() {
  myWindow = window.open("", "", "width=100, height=100");
}

function resizeWin() {
  myWindow.resizeTo(250, 250);
  myWindow.focus();
}
</script>

</body>
</html>

The resizeTo() method resizes a window to the specified width and height.

resizeTo(width,height);

Parameter Values

Parameter Type Description
width Number Required. Sets the width of the window, in pixels
heightNumber Required. Sets the height of the window, in pixels



PreviousNext

Related