与浏览器窗口互动。您可以使用此 API 获取有关已打开窗口的信息,以及打开、修改和关闭窗口。您也可以监听窗口的打开、关闭和其激活事件。

类型

windows.WindowType
浏览器窗口的类型。
windows.WindowState
浏览器窗口的状态。
windows.Window
有关一个浏览器窗口的信息。
windows.CreateType
指定要创建的浏览器窗口的类型。

属性

windows.WINDOW_ID_NONE
windowId 值表示不存在浏览器窗口。
windows.WINDOW_ID_CURRENT
windowId 值表示当前窗口。

函数

windows.get()
指定其 ID,获取一个窗口的细节。
windows.getCurrent()
获取当前窗口。
windows.getLastFocused()
获取最近获得焦点的窗口,通常它是“顶部”的窗口。
windows.getAll()
获取所有窗口。
windows.create()

创建新窗口。

windows.update()
更新一个窗口的属性。使用此项对移动、调整大小、聚焦/取消聚焦等。
windows.remove()
关闭一个窗口及其所有标签页。

事件

windows.onCreated
一个窗口创建时触发。
windows.onRemoved
一个窗口关闭时触发。
windows.onFocusChanged
当前有焦点的窗口改变时触发。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
CreateTypeChrome Full support Yes
Notes
Full support Yes
Notes
Notes `detached_panel` is not supported.
Edge Full support 14
Notes
Full support 14
Notes
Notes `panel` and `detached_panel` are not supported.
Firefox Full support 45Opera Full support Yes
Notes
Full support Yes
Notes
Notes `detached_panel` is not supported.
Firefox Android No support No
WINDOW_ID_CURRENTChrome Full support 18Edge Full support 14Firefox Full support 45Opera Full support 15Firefox Android No support No
WINDOW_ID_NONEChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
WindowChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
WindowStateChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
WindowTypeChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
createChrome Full support YesEdge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes 'url' and 'tabId options can't both be set together.
Notes The returned 'Window' object contains the 'tabs' property only from version 52 onwards.
Opera Full support YesFirefox Android No support No
getChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
getAllChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
getCurrentChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
getLastFocusedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
onCreatedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
onFocusChangedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
onRemovedChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
removeChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
updateChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

Edge 的不兼容

Edge 中不支持 Promises。需使用回调。

Chrome incompatibilities

windows

  • In Firefox onFocusChanged will trigger multiple times for a given focus change.

Example extensions

声明

此 API 基于 Chromium 的 chrome.windows API。此文档基于 Chromium 代码中的 windows.json

Microsoft Edge 兼容性数据由微软公司提供,并包含在创作共用 署名 3.0美国许可证下。

文档标签和贡献者

此页面的贡献者: yfdyh000
最后编辑者: yfdyh000,