Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Browser and Web APIs

The window.open() method

Reference for window.open(): open a new tab or popup window, choose a target, pass window features, use noopener, and handle popup blockers.

window.open() asks the browser to open a URL in a new tab or window, or to reuse a named one. It returns a reference to the new window so your code can talk to it, or null when the browser refused or when you asked for noopener.

Browsers treat unsolicited popups as abuse, so open() normally works only while the page is handling a user action such as a click. Called from a timer, a network callback or on page load, it is usually blocked. For a plain "open in a new tab" link, an <a target="_blank" rel="noopener"> element is simpler and works without JavaScript.

JavaScript
const win = window.open("https://example.com/", "_blank", "noopener");

Try it

Open a popup and check the result

The preview runs in a sandbox that does not allow popups, so you will see the blocked branch here. On a normal page, the same code opens a small window.

A link as a fallback

The real link keeps working for people who disable scripts, and the handler only adds behavior on top.

Syntax

JavaScript
window.open()
window.open(url)
window.open(url, target)
window.open(url, target, windowFeatures)
Name Description
url Optional string. The address to load. Relative URLs resolve against the current page. An empty string or omitted value opens about:blank.
target Optional string. "_blank" (default) opens a new browsing context. "_self", "_parent" and "_top" reuse the current one or an ancestor. Any other name reuses a window with that name or creates one.
windowFeatures Optional comma-separated string such as "popup,width=500,height=400,left=100,top=80". Also accepts noopener and noreferrer.

Return value: a WindowProxy for the new or reused window, or null if it was blocked, or if noopener or noreferrer was requested.

Exceptions: a SyntaxError DOMException if the URL cannot be parsed.

Usage notes

  • User activation matters. Call open() directly inside a click or keypress handler. Calling it after an await can lose the activation in some browsers.
  • Always add noopener for third-party URLs. Without it, the new page can reach back through window.opener. Links with target="_blank" get this behavior automatically in current browsers, but window.open() calls do not.
  • width, height and popup. Providing size features, or popup, asks for a minimal popup window. Many browsers still decide for themselves, and mobile browsers usually open a tab.
  • Check for null. If you need the window object (for postMessage() or close()), test the result and show a fallback link when it is missing.
  • Same-origin only for access. You can read win.document only when the opened page has the same origin. Cross-origin windows expose a small safe subset such as closed and postMessage().
  • close() is limited. A script can close windows it opened, not arbitrary tabs.
  • Prefer links. Search engines, screen readers and middle-click all work better with real anchors.

Browser support

Supported in every browser, but popup blocking and the exact meaning of window features differ between browsers and devices.