TabClose

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The non-standard, Firefox-only, TabClose event is sent by Firefox when a tab is closed.

Only Firefox itself and Firefox XPCOM-based add-ons can receive this event. XPCOM add-ons have been obsoleted by BrowserExtensions. If you're writing an add-on, please use tabs.onRemoved to detect when a tab is removed.

If you're writing code for the Web, you can't specifically determine when a tab is closed; however, you can detect when the current document closes by watching for an unload event.

General info

Specification
Firefox add-ons specific
Interface
Event
Bubbles
Yes
Cancelable
No
Target
tab
Default Action
None

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 Whether the event normally bubbles or not
cancelable Read only Boolean Whether the event is cancellable or not?

The target element can also be used as a DOM Window.

Example

This example listens for the TabClose event and, when it occurs, looks in the closing tab for a <textarea> element with the ID "myEditor"; if it's found, the element's text is sent to a function called saveDocument() for processing.

window.addEventListener("TabClose", function(event) {
  var editor = event.target.document.getElementById("myEditor");

  if (editor) {
    saveDocument(editor.value);
  }
}, false);

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, teoli, ethertank, louisremi
 Last updated by: Sheppy,