Close a window from script
Closes windows the script opened; ordinary tabs cannot be closed by script.
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
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 1 | 2008-12-11 | None |
| Edge | Supported | 12 | 2015-07-29 | None |
| Firefox | Supported | 1 | 2004-11-09 | None |
| Safari | Supported | 1 | 2003-06-23 | None |
| Safari on iPhone | Supported | 1 | 2007-06-29 | All iOS browsers use WebKit |
| Chrome on Android | Supported | 18 | 2012-06-27 | None |
| Samsung Internet | Supported | 1.0 | 2013-04-27 | None |
How a site asks for it
| API | window.close(); window.closed |
| Browser compat keys | api.Window.closeapi.Window.closed |
| How access is granted | none |
| What the user sees | None (no browser prompt) |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| Activation | none |
| How long it lasts | One-shot |
| How to take it back | Nothing to revoke (no permission is stored) |
| Inside an iframe | Only script-closable windows; frames cannot close their parent |
Typical flow
- Script calls window.close()
- If the window is script-closable, it closes
- 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
| Type | Example | Apps |
|---|---|---|
| social | A Sign in with Google window closes itself after you approve. | Spotify, Canva |
| payments | A PayPal pop up closes after you confirm, returning you to the shop. | PayPal |
| games | A browser game portal closes its leaderboard pop up after you pick a player. | None named |
| security | A phishing flow opens and closes windows quickly to hide a redirect. | None named |
| live | A pop out chat window shuts itself when the stream ends. | Twitch |
| enterprise | A 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
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 1 of 5 | How revealing the data is |
| Utility | 2 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough identifying entropy, when known |
History
- 2012, Firefox 10: close() restricted to script-opened windows
Related capabilities
Related
- Open popup or new window. Can open a new tab or window, but only right after you tap or click
Sources
How well checked: Based on official documentation.