Home | History | Annotate | Download | only in static
      1 <div id="pageData-name" class="pageData">Windows</div>
      2 
      3 <!-- BEGIN AUTHORED CONTENT -->
      4 <p id="classSummary">
      5 Use the <code>chrome.windows</code> module
      6 to interact with browser windows.
      7 You can use this module to
      8 create, 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>
     16 To use the windows API,
     17 you must declare the "tabs" permission
     18 in <a href="manifest.html">manifest.json</a>.
     19 (No, that isn't a typo &mdash;
     20 the window and tabs modules interact so closely we
     21 decided to just share one permission between them.)
     22 For 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
     35 take an optional <var>windowId</var> parameter,
     36 which defaults to the current window.
     37 </p>
     38 
     39 <p>The <em>current window</em> is the window that
     40 contains the code that is currently executing.
     41 It's important to realize that this can be
     42 different from the topmost or focused window.
     43 </p>
     44 
     45 <p>For example, say an extension
     46 creates a few tabs or windows from a single HTML file,
     47 and that the HTML file
     48 contains a call to
     49 <a href="tabs.html#method-getSelected">chrome.tabs.getSelected</a>.
     50 The current window is the window that contains the page that made
     51 the 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>,
     55 the value of the current window falls back to the last active window. Under some
     56 circumstances, there may be no current window for background pages.
     57 </p>
     58 
     59 <h2 id="examples"> Examples </h2>
     60 
     61 <p>
     62 You 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>
     64 directory.
     65 Another 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
     67 of the
     68 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/tabs/inspector/">inspector</a>
     69 example.
     70 For 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