视窗

内容

  1. 清单
    1. <a>h3Name</a>
  2. 当前视窗
    1. <a>h3Name</a>
  3. 范例
    1. <a>h3Name</a>
  4. API 参考: chrome.windows
    1. 属性
      1. WINDOW_ID_NONE
    2. 方法
      1. create
      2. get
      3. getAll
      4. getCurrent
      5. getLastFocused
      6. remove
      7. update
    3. 事件
      1. onCreated
      2. onFocusChanged
      3. onRemoved
    4. 类型
      1. Window

For information on how to use experimental APIs, see the chrome.experimental.* APIs page.

视窗

使用chrome.windows模块与浏览器视窗进行交互。 你可以使用这个模块在浏览器中创建、修改和重新排列视窗。

Two windows, each with one tab

清单

要使用视窗 API,你必须在manifest.json声明"tabs"的权限 。(不,这不是一个错字 - 窗口和标签模块的互动如此密切,我们决定它们共享一个权限。)例如:

{
  "name": "My extension",
  ...
  **"permissions": ["tabs"]**,
  ...
}

当前视窗

很多扩展系统的功能有一个可选的windowId参数,其默认值为当前视窗。

当前视窗是指包含当前正在执行的代码的视窗。重要的是要认识到,它可以跟最顶层或有焦点的视窗不一样。

例如,假设一个扩展从一个单一的HTML文件中创建了一些标签或视窗,而这个HTML文件包含一个chrome.tabs.getSelected的调用 。 当前视窗是指那个包含了发起调用的页面的视窗,不管它是不是最顶层视窗。

背景页这个例子中 ,当前视窗就是最后一个活动视窗。在某些情况下,背景页可能没有当前视窗。

范例

你可以在examples/api/windows 目录下找到一些使用windows模块的简单范例。另外一个范例是在tabs_api.html文件中的检查器范例。 对于其他的例子和查看源代码的帮助,参见示例

API 参考: chrome.windows

属性

WINDOW_ID_NONE

chrome.windows.WINDOW_ID_NONE

WINDOW_ID_NONE( optional enumerated Type array of 整数 )

Undocumented.

这个windowId值表示没有Chrome浏览器窗口的情况。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

方法

create

void chrome.windows.create(, object createData, function callback)

Undocumented.

使用任何可选大小、位置或者默认提供的URL来创建(打开)一个新的浏览器。

参数

createData( optional enumerated Type array of object可选,对象 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

url( optional enumerated Type array of string or array of string 可选,字符串或者字符串数组)

Undocumented.

一个或者一组在视窗作为标签打开的URL。完全合格的URL必须包括一个类型(即'http://www.google.com',不是'www.google.com')。相对URL将与扩展内的当前页相关。默认为新的标签页面。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

tabId( optional enumerated Type array of integer可选,整数 )

Undocumented.

你想要在新视窗选定的标签的id。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

left( optional enumerated Type array of integer 可选,整数 )

Undocumented.

新视窗相对于屏幕的左边缘的位置的像素值。如果没有指定,那么新的视窗从最后一个有焦点的视窗自然偏移。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

top( optional enumerated Type array of integer可选,整数 )

Undocumented.

新视窗相对于屏幕的上边缘的位置的像素值。如果没有指定,那么新的视窗从最后一个有焦点的视窗自然偏移。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

width( optional enumerated Type array of integer可选,整数 )

Undocumented.

新视窗的像素宽度。如果没有指定,默认为自然宽度。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

height( optional enumerated Type array of integer可选,整数 )

Undocumented.

新视窗的像素高度。如果没有指定,默认为自然高度。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

incognito( optional enumerated Type array of boolean可选,Boolean类型 )

Undocumented.

新视窗是否是隐身。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

type( optional enumerated Type array of string ["normal", "popup"]可选,枚举字符串["normal", "popup"] )

Undocumented.

指定新建浏览器视窗的类型。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

callback( optional enumerated Type array of function可选,函数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

The callback parameter should specify a function that looks like this:

如果指定了回调参数,它应该指定一个如下所示函数:

function(Window window) {...};

window( optional enumerated Window 可选,视窗 array of paramType )

Undocumented.

包含新创建视窗的详细信息。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

get

void chrome.windows.get(, integer windowId, function callback)

Undocumented.

获取有关窗口的详细信息。

参数

windowId( optional enumerated Type array of integer整数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

callback( optional enumerated Type array of function函数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

Callback function

如果指定了回调参数,它应该指定一个如下所示函数:

If you specify the callback parameter, it should specify a function that looks like this:

function(Window window) {...};

window( optional enumerated Window array of paramType )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

getAll

void chrome.windows.getAll(, object getInfo, function callback)

Undocumented.

获得所有的视窗。

参数

getInfo( optional enumerated Type array of object可选,对象 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

populate( optional enumerated Type array of boolean 可选,Boolean类型)

Undocumented.

如果是true表示每个视窗对象都有一个包含该视窗所有标签的tabs属性。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

callback( optional enumerated Type array of function函数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

回调参数应该指定一个如下函数:

If you specify the callback parameter, it should specify a function that looks like this:

function(array of Window windows) {...};

windows( optional enumerated Type array of Window array of paramType paramType )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

getCurrent

void chrome.windows.getCurrent(, function callback)

Undocumented.

获得当前视窗

参数

callback( optional enumerated Type array of function 函数)

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

如果指定了回调参数,它应该指定一个如下所示函数:

If you specify the callback parameter, it should specify a function that looks like this:

function(Window window) {...};

window( optional enumerated Window array of paramType )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

getLastFocused

void chrome.windows.getLastFocused(, function callback)

Undocumented.

获取最近有焦点的视窗 — 一般是最顶层的视窗。

参数

callback( optional enumerated Type array of function 函数)

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

如果指定了回调参数,它应该指定一个如下所示函数:

If you specify the callback parameter, it should specify a function that looks like this:

function(Window window) {...};

window( optional enumerated Window array of paramType )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

remove

void chrome.windows.remove(, integer windowId, function callback)

Undocumented.

关闭一个视窗以及其包含的所有标签。

参数

windowId( optional enumerated Type array of integer整数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

callback( optional enumerated Type array of function 可选,函数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

The callback parameter should specify a function that looks like this:

如果指定了回调参数,它应该指定一个如下所示函数:

function() {...};

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

update

void chrome.windows.update(, integer windowId, object updateInfo, function callback)

Undocumented.

更新一个视窗的属性。只指定那些你希望修改的属性,未指定的属性将保持不变。

参数

windowId( optional enumerated Type array of integer整数 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

updateInfo( optional enumerated Type array of object对象 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

left( optional enumerated Type array of integer 可选,整数 )

Undocumented.

视窗相对屏幕左边界进行移动的像素偏移值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

top( optional enumerated Type array of integer 可选,整数 )

Undocumented.

视窗相对屏幕上边界进行移动的像素偏移值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

width( optional enumerated Type array of integer可选,整数 )

Undocumented.

视窗宽度调整的像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

height( optional enumerated Type array of integer可选,整数 )

Undocumented.

视窗高度调整的像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

focused( optional enumerated Type array of boolean可选,Boolean类型 )

Undocumented.

如果是true,将该视窗提至前面。否则,将z-order上下一视窗提至前面。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

callback( optional enumerated Type array of function 可选,函数)

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

Returns

回调函数

The callback parameter should specify a function that looks like this:

如果指定了回调参数,它应该指定一个如下所示函数:

function(Window window) {...};

window( optional enumerated Window array of paramType )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

事件

onCreated

chrome.windows.onCreated.addListener(function(Window window) {...});

Undocumented.

当一个新视窗被创建时触发。

参数

window( optional enumerated Window array of paramType )

Undocumented.

被创建窗体的详细信息。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

onFocusChanged

chrome.windows.onFocusChanged.addListener(function(integer windowId) {...});

Undocumented.

当前获得焦点窗口改变时触发。Will be chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one chrome window to another.

Parameters

windowId( optional enumerated Type array of integer )

Undocumented.

ID of the newly focused window.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

onRemoved

chrome.windows.onRemoved.addListener(function(integer windowId) {...});

Undocumented.

当一个视窗被关闭时触发。

参数

windowId( optional enumerated Type array of integer 整数)

Undocumented.

被关闭视窗的ID。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

类型

Window

paramName( optional enumerated Type array of object视窗,对象 )

Undocumented.

Description of this parameter from the json schema.

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

id( optional enumerated Type array of integer 整数)

Undocumented.

视窗的ID。视窗ID在一个浏览器会话中是唯一的。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

focused( optional enumerated Type array of boolean )

Undocumented.

该窗口是否当前焦点窗口。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

top( optional enumerated Type array of integer整数 )

Undocumented.

窗体相对屏幕上边缘的偏移像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

left( optional enumerated Type array of integer整数 )

Undocumented.

窗体相对屏幕左边缘的偏移像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

width( optional enumerated Type array of integer整数 )

Undocumented.

窗体宽度像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

height( optional enumerated Type array of integer整数 )

Undocumented.

窗体高度像素值。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

tabs( optional enumerated Type array of Tab可选,标签数组 array of paramType paramType )

Undocumented.

表征窗体所包含标签的数组。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

incognito( optional enumerated Type array of boolean )

Undocumented.

窗体是否隐藏。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.

type( optional enumerated Type array of string ["normal", "popup", "app"] )

Undocumented.

浏览器视窗类型。

This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.