Skip to Content
Platform.Ontology

Close a window from script

Closes windows the script opened; ordinary tabs cannot be closed by script.

Does something on your deviceThings a page can doWindows and navigationWeb browsersWhile you use it

In one line

Can close windows it opened itself, but not your regular tabs

Closes windows the script opened; ordinary tabs cannot be closed by script.

A page can close a popup it created (for example after sign in), but it cannot kill the tab the person opened, which prevents sites from trapping or hiding.

What it can and can't do

What the user does: Nothing for its own windows. It happens when you finish a sign in or tap Done.

It can

  • Close a popup or window that the page opened
  • Close a sign in window when it is finished
  • Close a window after a payment completes

It cannot

  • Close a tab you opened yourself
  • Close a window it did not open
  • Close the whole browser
  • Close a tab with other history in it in most browsers

Browser support

BrowserStatusFirst versionReleasedNote
ChromeSupported12008-12-11None
EdgeSupported122015-07-29None
FirefoxSupported12004-11-09None
SafariSupported12003-06-23None
Safari on iPhoneSupported12007-06-29All iOS browsers use WebKit
Chrome on AndroidSupported182012-06-27None
Samsung InternetSupported1.02013-04-27None

How a site asks for it

APIwindow.close(); window.closed
Browser compat keysapi.Window.close
api.Window.closed
How access is grantednone
What the user seesNone (no browser prompt)
Needs a secure context (HTTPS)No
Needs a user gestureNo
Activationnone
How long it lastsOne-shot
How to take it backNothing to revoke (no permission is stored)
Inside an iframeOnly script-closable windows; frames cannot close their parent

Typical flow

  1. Script calls window.close()
  2. If the window is script-closable, it closes
  3. Otherwise console warns and nothing happens

Data you get

Shape: none

No individual data fields. The signal is the access itself.

Technical limits

  • Script-closable only: opened by window.open, or the tab has a single session history entry (HTML spec)
  • Firefox adds dom.allow_scripts_to_close_windows (default false for non-script windows)
  • Chrome logs: Scripts may close only the windows that were opened by them
  • Cannot close the browser or other windows

The story

What it is

A page can close windows it opened, but not your ordinary tabs.

For you

A small sign in or payment window closes itself when it is done. A normal page cannot shut your other tabs.

For makers

Makers use it to tidy up their own pop ups after sign in or payment. The browser blocks the rest so sites cannot slam your tabs shut.

Where you see it

TypeExampleApps
socialA Sign in with Google window closes itself after you approve.Spotify, Canva
paymentsA PayPal pop up closes after you confirm, returning you to the shop.PayPal
gamesA browser game portal closes its leaderboard pop up after you pick a player.None named
securityA phishing flow opens and closes windows quickly to hide a redirect.None named
liveA pop out chat window shuts itself when the stream ends.Twitch
enterpriseA company tool closes its single sign on pop up when login is done.Okta

Risks

  • Vanishing windows
  • Hiding redirects

Good uses and abuse

Legitimate uses

  • Close OAuth popup after login

Known abuse

  • Pop-under cleanup
  • Hiding tracking popups

Scores

ScoreValueMeaning
Sensitivity1 of 5How revealing the data is
Utility2 of 5How useful it is to honest apps
Friction0 of 5How much the user has to do
Fingerprint bitsNot ratedRough identifying entropy, when known

History

  • 2012, Firefox 10: close() restricted to script-opened windows

Sources

How well checked: Based on official documentation.

On this page