JavaScript Window open() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

window.open() loads a resource into a new or existing browsing context (tab, window, or named frame) (MDN). Success returns a Window reference; a blocker returns null.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call window.open. Start with this line.

JavaScript
open(url?, target?, windowFeatures?)
CallWhat it does
open(url?, target?, windowFeatures?)Primary signature.
window.open(...)Call with the arguments your case needs.

Built into the browser. Call window.open(...) (or the global open(...)) — no import required.

Library declarations
JavaScript
open(url?, target?, windowFeatures?)

Parameters

ParameterDescription
urlOptional. Resource to load; "" / omitted → blank page
targetOptional. Context name, or _blank (default), _self, _parent, _top

Return Value

Return ValueDescription
*WindowProxy or null

JavaScript Examples

Example 1 — Basic Open

Open a blank named window from a button click.

JavaScript
// inside a click handler
const popup = window.open("", "HelpPanel", "width=600,height=400");

if (popup) {
  popup.document.write("

Help

"); popup.document.close(); popup.focus(); console.log("opened"); }
Try It Yourself

How It Works

  1. Call open. Empty URL → blank document.
  2. Name + size. HelpPanel with width/height.
  3. Fill content. Demo pattern: document.write then close().
  4. Focus. Bring the new window forward when allowed.

Example 2 — Null Check (Blocker)

Always branch when the return value might be null.

JavaScript
const popup = window.open("", "ToolPanel", "width=400,height=300");

if (!popup) {
  console.log("blocked");
} else {
  console.log("ok");
}
Try It Yourself

How It Works

  1. Open. Request a small blank window.
  2. Check. Blockers return null — they do not throw.
  3. Branch. Show a message or fallback UI when blocked.
  4. Tip. Prefer click handlers over timers / page-load opens.

Example 3 — Size & Position

Use windowFeatures for width, height, left, and top.

JavaScript
const features = "left=100,top=100,width=320,height=320";
const popup = window.open("", "SizedWin", features);

if (popup) {
  console.log("sized");
}
Try It Yourself

How It Works

  1. Features string. Comma-separated name=value pairs.
  2. Min size. MDN: width/height minimum is 100.
  3. Clamping. Browsers keep the popup inside the work area.
  4. Mobile. Size/position requests are often ignored.

Example 4 — noopener

Isolate the opened page; open() returns null.

JavaScript
const popup = window.open(
  "",
  "_blank",
  "noopener,width=400,height=300"
);

console.log(popup); // null when noopener applies
Try It Yourself

How It Works

  1. Feature. Add noopener in the features string.
  2. No opener. The new page cannot use window.opener.
  3. Return. MDN: with noopener, the return value is null.
  4. When to use. Safer for untrusted URLs you only need to open.

Example 5 — Named Window Reuse

The same target name reuses one window instead of stacking many.

JavaScript
function openHelp() {
  const help = window.open("", "AppHelp", "width=500,height=400");
  if (!help) return;
  help.focus();
  console.log("help ready");
}

// second click with "AppHelp" → same window, then focus()
Try It Yourself

How It Works

  1. Stable name. Reuse "AppHelp" every time.
  2. One context. MDN: prefer named targets over many _blank windows.
  3. Focus. Bring the existing window forward.
  4. Closed? If the user closed it, the next open creates it again.

Browser Support

Window.open() is marked Limited availability on MDN — core opening works widely, but popup UI, features, and return values (e.g. noopener) vary.

✓ Limited availability

open()

Open browsing contexts; treat features and blockers as browser-dependent.

95% Core tag support
Chrome Yes
Full core support
Edge Yes
Full core support
Firefox Yes
Full core support
Safari Yes
Full core support
Opera Yes
Full core support
HTML element 100% supported

Bottom line: Always null-check. Prefer a user click. Test popup size and noopener in your target browsers.

Frequently Asked Questions

It loads a URL into a new or existing browsing context (tab, window, or iframe name). On success it returns a WindowProxy reference; if blocked, it returns null.
No. It is not Deprecated, Experimental, or Non-standard. MDN marks Window.open() as Limited availability because some features and popup behavior differ across browsers.
Optional url, optional target (name or _blank/_self/_parent/_top), and optional windowFeatures (comma-separated list such as popup, width, height, left, top, noopener).
The browser blocked the new context — usually a popup blocker when open() was not tied to a direct user gesture (click). Always check the return value before using it.
With noopener in windowFeatures, the new window does not get window.opener, and open() returns null. That isolates the opener from the opened page.
Prefer a normal link with target and rel when you only need navigation. Use window.open() when you need a Window reference (close, focus, size) after a user click.

Next: print()

Open the browser’s print dialog for the current document.

print() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful