This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28622 - window.close() should not close the window when unload or beforeunload events are running
Summary: window.close() should not close the window when unload or beforeunload events...
Status: RESOLVED MOVED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-11 15:40 UTC by Gijs
Modified: 2019-03-29 19:13 UTC (History)
2 users (show)

See Also:


Attachments

Description Gijs 2015-05-11 15:40:17 UTC
https://html.spec.whatwg.org/multipage/browsers.html#dom-window-close currently says:

> The close() method on Window objects should, if all the following conditions
> are met, close the browsing context A:
>
> * The corresponding browsing context A is script-closable.
> * The responsible browsing context specified by the incumbent settings object
>   is familiar with the browsing context A.
> * The responsible browsing context specified by the incumbent settings object
>   is allowed to navigate the browsing context A.
>
> A browsing context is script-closable if it is an auxiliary browsing context
> that was created by a script (as opposed to by an action of the user), or if
> it is a top-level browsing context whose session history contains only one
> Document.

Consider the following HTML:

<body>
<script>
window.addEventListener("beforeunload", function() { window.close() }, false);
</script>
</body>

If I understand the current spec correctly, if a page like this is loaded as the first document in a browsing context, and the user then attempts to navigate the page to any other page/address, say, https://whatwg.org/, then per spec the browsing context should close.

This does not seem optimal to me, and as best I can tell, is not what Blink implements (window.close gets ignored), while Trident prompts the user, and Gecko currently reacts as per spec in this case. I think the Blink behaviour makes some sense, and I think the spec should be brought in line with it.
Comment 1 Domenic Denicola 2019-03-29 19:13:02 UTC
https://github.com/whatwg/html/issues/4466