• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<div id="pageData-name" class="pageData">Windows</div>
2
3<!-- BEGIN AUTHORED CONTENT -->
4<p id="classSummary">
5Use the <code>chrome.windows</code> module
6to interact with browser windows.
7You can use this module to
8create, modify, and rearrange windows in the browser.
9</p>
10
11<img src="images/windows.png"
12     width="256" height="76" alt="Two windows, each with one tab" />
13
14<h2 id="manifest">Manifest</h2>
15<p>
16To use the windows API,
17you must declare the "tabs" permission
18in <a href="manifest.html">manifest.json</a>.
19(No, that isn't a typo &mdash;
20the window and tabs modules interact so closely we
21decided to just share one permission between them.)
22For example:
23</p>
24
25<pre>{
26  "name": "My extension",
27  ...
28  <b>"permissions": ["tabs"]</b>,
29  ...
30}</pre>
31
32<h2 id="current-window">The current window</h2>
33
34<p>Many functions in the extension system
35take an optional <var>windowId</var> parameter,
36which defaults to the current window.
37</p>
38
39<p>The <em>current window</em> is the window that
40contains the code that is currently executing.
41It's important to realize that this can be
42different from the topmost or focused window.
43</p>
44
45<p>For example, say an extension
46creates a few tabs or windows from a single HTML file,
47and that the HTML file
48contains a call to
49<a href="tabs.html#method-getSelected">chrome.tabs.getSelected</a>.
50The current window is the window that contains the page that made
51the call, no matter what the topmost window is.
52</p>
53
54<p>In the case of the <a href="background_pages.html">background page</a>,
55the value of the current window falls back to the last active window. Under some
56circumstances, there may be no current window for background pages.
57</p>
58
59<h2 id="examples"> Examples </h2>
60
61<p>
62You can find simple examples of using the windows module in the
63<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/windows/">examples/api/windows</a>
64directory.
65Another example is in the
66<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.html?content-type=text/plain">tabs_api.html</a> file
67of the
68<a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/tabs/inspector/">inspector</a>
69example.
70For other examples and for help in viewing the source code, see
71<a href="samples.html">Samples</a>.
72</p>
73
74<!-- END AUTHORED CONTENT -->
75