tabs.onAttached
Fired when a tab is attached to a window, for example because it was moved between windows.
Syntax
browser.tabs.onAttached.addListener(listener)
browser.tabs.onAttached.removeListener(listener)
browser.tabs.onAttached.hasListener(listener)
Events have three functions:
addListener(callback)
- Adds a listener to this event.
removeListener(listener)
- Stop listening to this event. The
listener
argument is the listener to remove. hasListener(listener)
- Check whether
listener
is registered for this event. Returnstrue
if it is listening,false
otherwise.
addListener syntax
Parameters
callback
-
Function that will be called when this event occurs. The function will be passed the following arguments:
tabId
integer
. ID of the tab that was attached to a new window.
attachInfo
object
. ID of the new window, and index of the tab within it.
Additional objects
attachInfo
newWindowId
integer
. ID of the new window.newPosition
integer
. Index position that the tab has in the new window.
Examples
Listen for attach events, and log the info:
function handleAttached(tabId, attachInfo) {
console.log("Tab: " + tabId + " attached");
console.log("New window: " + attachInfo.newWindowId);
console.log("New index: " + attachInfo.newPosition);
}
browser.tabs.onAttached.addListener(handleAttached);
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
onAttached | ChromeFull supportYes | EdgeFull support15 | FirefoxFull support45 | OperaFull supportYes | SafariFull support14 | Firefox for AndroidFull support54 |
Legend
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Acknowledgements
This API is based on Chromium's chrome.tabs
API. This documentation is derived from tabs.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.