By Xah Lee. Date: . Last updated: .

The method lets you open a new URL. Example:

Click Me to Goto JavaScript In Depth

Here's the code.

<p id="open42311">Click Me to Goto JavaScript In Depth</p>
const openIt = ((x) => { open( "", "_blank"); });

document.getElementById("open42311"). addEventListener( "click", openIt, false); Parameters accepts 4 parameters, all optional. Only the first one is really necessary.

  1. URL (string)
  2. a window name (string).
  3. spec for window parameters. (string) Such as window size, position, show scrollbar, toolbar, etc.
  4. true or false. If true, whether to replace the current URL in history list.

The window name is a string, and some value has special meaning:

The “window name” concept and their special names is from old HTML spec (1990s), where a anchor <a> can have a name attribute. This “name” attribute is also used by frames:

Window Parameter Spec (size, position, toolbars)

The 3rd parameter to is a string. The purpose is to specify the newly opened window's position, size, whether to show toolbars, url field, etc. It is rarely used today. Most browsers will block popup anyway. There are many implicit restrictions by different browsers because spammer abused this feature to make it looks identical to a system alert (such as out of memory), and trick people to click, resulting visiting ad sites or malware sites.

Here's a example using the parameter:

function popup () { open( "",
 "width=640,height=480,menubar=no,scrollbar=no"); }
document .getElementById("popup44429"). addEventListener( "click", popup, false);

click me to see

For a complete list, see: Return Value return a new window object.

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. CSS
  3. JavaScript
  4. JS Obj Ref
  5. DOM
  6. SVG
  7. Blog