aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.7/packages/api-utils/docs/tab-browser.md
blob: 295fcc79c6d5678ced6914c6229e0b2c0a95e74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- contributed by Dietrich Ayala [dietrich@mozilla.com]  -->

The `tab-browser` module is a low-level API that provides privileged
access to browser tab events and actions.

Introduction
------------

The `tab-browser` module contains helpers for tracking tabbrowser elements
and tabs, as well as a few utilities for actions such as opening a new
tab, and catching all tab content loads.

This is a low-level API that has full privileges, and is intended to be used
by SDK internal modules. If you just need easy access to tab events for your
add-on, use the Tabs module (JEP 110).

<api name="activeTab">
@property {element}
The XUL tab element of the currently active tab.
</api>

<api name="addTab">
@function
Adds a new tab.

**Example**

    var tabBrowser = require("tab-browser");
    tabBrowser.addTab("http://google.com");

    var tabBrowser = require("tab-browser");
    tabBrowser.addTab("http://google.com", {
      inBackground: true
    });

    var tabBrowser = require("tab-browser");
    tabBrowser.addTab("http://google.com", {
      inNewWindow: true,
      onLoad: function(tab) {
        console.log("tab is open.");
      }
    });

@returns {element}
The XUL tab element of the newly created tab.

@param URL {string}
The URL to be opened in the new tab.

@param options {object}
Options for how and where to open the new tab.

@prop [inNewWindow] {boolean}
An optional parameter whose key can be set in `options`.
If true, the tab is opened in a new window. Default is false.

@prop [inBackground] {boolean}
An optional parameter whose key can be set in `options`.
If true, the tab is opened adjacent to the active tab, but not
switched to. Default is false.

@prop [onLoad] {function}
An optional parameter whose key can be set in `options`.
A callback function that is called once the tab has loaded.
The XUL element for the tab is passed as a parameter to
this function.
</api>

<api name="Tracker">
@function
Register a delegate object to be notified when tabbrowsers are created
and destroyed.

The onTrack method will be called once per pre-existing tabbrowser, upon
tracker registration.

**Example**

    var tabBrowser = require("tab-browser");
    let tracker = {
      onTrack: function(tabbrowser) {
        console.log("A new tabbrowser is being tracked.");
      },
      onUntrack: function(tabbrowser) {
        console.log("A tabbrowser is no longer being tracked.");
      }
    };
    tabBrowser.Tracker(tracker);

@param delegate {object}
Delegate object to be notified each time a tabbrowser is created or destroyed.
The object should contain the following methods:

@prop [onTrack] {function}
Method of delegate that is called when a new tabbrowser starts to be tracked.
The tabbrowser element is passed as a parameter to this method.

@prop [onUntrack] {function}
Method of delegate that is called when a tabbrowser stops being tracked.
The tabbrowser element is passed as a parameter to this method.
</api>

<api name="TabTracker">
@function
Register a delegate object to be notified when tabs are opened and closed.


The onTrack method will be called once per pre-existing tab, upon
tracker registration.

**Example**

    var tabBrowser = require("tab-browser");
    let tracker = {
      onTrack: function(tab) {
        console.log("A new tab is being tracked.");
      },
      onUntrack: function(tab) {
        console.log("A tab is no longer being tracked.");
      }
    };
    tabBrowser.TabTracker(tracker);

@param delegate {object}
Delegate object to be notified each time a tab is opened or closed.
The object should contain the following methods:

@prop [onTrack] {function}
Method of delegate that is called when a new tab starts to be tracked.
The tab element is passed as a parameter to this method.

@prop [onUntrack] {function}
Method of delegate that is called when a tab stops being tracked.
The tab element is passed as a parameter to this method.
</api>