JavaScript: Open URL

By Xah Lee. Date: . Last updated: .

The method lets you open a new URL. Example:

Click Me to open JavaScript In Depth

Here is 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, windowName, windowFeatures, replaceCurrent).

The url is a URL to open. Can be empty string.

All other parameters are optional.

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

A name of the window. name can be arbitrary. If that named window already exist, open in that window, else new window/tab.
Open in new window (or tab). This is default
Open in parent frame.
Open in current window.
Open and replace framesets.

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

windowFeatures is spec for window parameters. Example: "width=640,height=480,menubar=no,scrollbar=no". It specifies window size, position, show scrollbar, toolbar, url field, etc.

Here is a example using the parameter:

const popup = (() => {


click me to see popup window.

replaceCurrent is true or false. If true, replace the current URL in history list.

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

JavaScript in Depth

DOM Scripting


DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc