W3cubDocs

/DOM Events

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 since Gecko 57 (Firefox 57 / Thunderbird 57 / SeaMonkey 2.54)
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 WebExtensions. 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
targetRead only EventTarget The event target (the topmost target in the DOM tree).
typeRead only DOMString The type of event.
bubblesRead only Boolean Whether the event normally bubbles or not.
cancelableRead 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

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/Events/TabClose