JavaScript Window method: open()
[this page | pdf | back links]
The open() method (when applied to Window objects
in the JavaScript
BOM) opens a new
browser window.
 
It
has the following syntax with the following parameters. It does not return a
value.
 
window.open(URL, name,
specifications, replace)
 
 
  | Parameter | Required / Optional | Description | 
 
  | URL | Optional | URL of
  page to open. If no URL is
  specified then a new window with about:blank
  is opened | 
 
  | name | Optional | The HTML target attribute
  (name) applicable to the window (e.g. _blank,
  …) | 
 
  | specifications | Optional | A comma-separated list
  of items, no whitespaces, see below | 
 
  | replace | Optional | Boolean specifying
  whether URL
  replaces the current entry in the history list (true) or creates a new entry (false) | 
 
Values supported by the specifications
parameter vary by browser but for some browsers include following:
 
 
  | Sub-Parameter | Options | Description | 
 
  | channelmode | yes|no|1|0 | Whether to display
  window in ‘theatre’ mode (default no) | 
 
  | directories | yes|no|1|0 | Obsolete. Whether to
  add directory buttons (default yes) | 
 
  | fullscreen | yes|no|1|0 | Whether to display in
  full-screen mode (defatul no) | 
 
  | height | pixels | Height of window (min
  100) | 
 
  | left | pixels | Left position of window
  (min 0) | 
 
  | location | yes|no|1|0 | Whether to display
  address field | 
 
  | menubar | yes|no|1|0 | Whether to display
  menubar | 
 
  | resizable | yes|no|1|0 | Whether window is
  resizable | 
 
  | scrollbars | yes|no|1|0 | Whether to display
  scrollbars | 
 
  | titlebar | yes|no|1|0 | Whether to display
  titlebar. Ignored unless calling application is HTML Application or trusted
  dialog box | 
 
  | toolbar | yes|no|1|0 | Whether to display
  browser toolbar | 
 
  | top | pixels | top position of window
  (min 0) | 
 
  | width | pixels | Width of window (min
  100) | 
 
EXAMPLE:
HTML USED IN THIS EXAMPLE:
| <!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
<button onclick="myOpen()">Open a new window</button><br>
<button onclick="myResizeBy()">Resize newly opened window: resizeBy(100,50)</button><br>
<button onclick="myResizeTo()">Resize newly opened window: resizeBy(400,400)</button><br>
<button onclick="myMoveBy()">Move newly opened window: moveBy(100,60)</button><br>
<button onclick="myMoveTo()">Move newly opened window: moveBy(300,350)</button><br>
<button onclick="myScroll()">Scroll newly opened window: scroll(80,20) [depreciated]</button><br>
<button onclick="myScrollBy()">Scroll newly opened window: scrollBy(30,60)</button><br>
<button onclick="myScrollTo()">Scroll newly opened window: scrollTo(70,30)</button><br>
<button onclick="myClose()">Close newly opened window</button>
<script>
var x;
function myOpen() {
  x = window.open("","newWindow", "width=300, height=300");
  x.document.write("<h3>Text in a new window - Long enough that window is likely to trigger scrolling, or adjust size to do so</h3>" +
    "Note: many of these functions seem to be supported only non-intuitives by some browsers<br>" +
    "1<br>2<br>3<br>4<br>5<br>6<br>7<br>" +
    "8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br><h4>End</h4>");
}
function myResizeBy() { x.resizeBy(100, 50); }
function myResizeTo() { x.resizeTo(400, 400); }
function myMoveBy() { x.moveBy(100, 60); }
function myMoveTo() { x.moveTo(300, 350); }
function myScroll() { x.Scroll(80, 20); }
function myScrollBy() { x.ScrollBy(30, 60); }
function myScrollTo() { x.scrollTo(70, 30); }
function myClose() { x.close(); }
</script>
</body>
</html>
 | 
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
| function isSupportedJavaScriptMethodWindowOpen() {
  return !!window.open;
} | 
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)