The close
event is executed when a request has been made to close the window when the user presses the close button.
If an event handler is placed on the window element, it can be prevented to close (see example below). Note that the close event is only fired when the user presses the close button on the titlebar; (i.e. not File -> Quit). The unload event should be used to capture all attempts to unload the window.
General info
- Specification
- XUL
- Interface
- Event
- Bubbles
- No
- Cancelable
- No
- Target
- window
- Default Action
- The window is closed.
Properties
Property | Type | Description |
---|---|---|
target Read only |
EventTarget |
The event target (the topmost target in the DOM tree). |
type Read only |
DOMString |
The type of event. |
bubbles Read only |
boolean |
Does the event normally bubble? |
cancelable Read only |
boolean |
Is it possible to cancel the event? |
Example
window.addEventListener("close", function( event ) { // make the close button ineffective event.preventDefault(); }, false);