By Xah Lee. Date: . Last updated: .

The method lets you open a new URL. Example:

Click Me to open JavaScript In Depth

Here's the code.

<span id="clickOpen62488">Click Me</span>
to open JavaScript In Depth
const clickOpen62488 = document.getElementById("clickOpen62488");

const openIt = (() => { open( "", "_blank"); });

clickOpen62488. 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:

const clickBox85509 = document. getElementById ('clickBox85509');

const popup = (() => {
 open( "",
 "width=640,height=480,menubar=no,scrollbar=no"); }

clickBox85509. addEventListener ( "click", popup, false);

click me to see

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

DOM How-To

Web Scripting Overview

HTML Input

Web Scripting Examples

Web Scripting Misc



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