Windows
3.4.6Using the Window Management API, your application can easily open and manipulate browser windows. This allows you to transform your traditional single-window web app into a multi-window native-like web application. The Window Management API enables applications to:
- open multiple windows;
- manipulate the position and size of opened windows;
- pass context data upon opening new windows;
- listen for and handle events related to opening and closing windows;
The Window Management API is accessible through the io.windows
object.
APIobject
Methods
findByIdmethod
Signature
(id: string) => WebWindow
Description
Finds a window by ID.
Parameters
Name | Type | Required | Description |
---|---|---|---|
id | string | Window ID. |
listmethod
Signature
() => WebWindow[]
mymethod
onWindowAddedmethod
Signature
(callback: (window: WebWindow) => void) => UnsubscribeFunction
Description
Notifies when a new window is opened.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (window: WebWindow) => void | Callback function to handle the event. Receives the added window as a parameter. Returns an unsubscribe function. |
onWindowGotFocusmethod
Signature
(callback: (window: WebWindow) => void) => UnsubscribeFunction
Description
Notifies when a window receives focus.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (window: WebWindow) => void | Callback function to handle the event. Receives the window instance as a parameter. Returns an unsubscribe function. |
onWindowLostFocusmethod
Signature
(callback: (window: WebWindow) => void) => UnsubscribeFunction
Description
Notifies when a window loses focus.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (window: WebWindow) => void | Callback function to handle the event. Receives the window instance as a parameter. Returns an unsubscribe function. |
onWindowRemovedmethod
Signature
(callback: (window: WebWindow) => void) => UnsubscribeFunction
Description
Notifies when a window is closed. For backwards compatibility, you can also use windowRemoved
.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (window: WebWindow) => void | Callback function to handle the event. Receives the removed window as a parameter. Returns an unsubscribe function. |
Boundsobject
Properties
Property | Type | Default | Required | Description |
---|---|---|---|---|
height | number | |||
left | number | |||
top | number | |||
width | number |
Settingsobject
Properties
Property | Type | Default | Required | Description |
---|---|---|---|---|
context | any | The initial window context. Accessible from {@link WebWindow#getContext} |
||
height | number | 400 | Window height. |
|
left | number | 0 | Distance of the top left window corner from the left edge of the screen. |
|
relativeDirection | RelativeDirection | "right" | Direction ( |
|
relativeTo | string | The ID of the window that will be used to relatively position the new window.
Can be combined with |
||
top | number | 0 | Distance of the top left window corner from the top edge of the screen. |
|
width | number | 400 | Window width. |
WebWindowobject
Properties
Property | Type | Default | Required | Description |
---|---|---|---|---|
id | string | |||
isFocused | boolean | |||
name | string |
Methods
closemethod
focusmethod
Signature
() => Promise<WebWindow>
Description
Attempts to activate and bring to foreground the window. It is possible to fail due to client browser settings.
getBoundsmethod
getChannelmethod
Signature
() => Promise<string>
Description
Retrieves the current Channel of the window, if any.
getContextmethod
Signature
() => Promise<any>
Description
Gets the current context object of the window.
getTitlemethod
Signature
() => Promise<string>
Description
Returns the title of the window.
getURLmethod
Signature
() => Promise<string>
Description
Gets the current URL of the window.
moveResizemethod
moveTomethod
Signature
(top?: number, left?: number) => Promise<WebWindow>
Description
Sets a new location of the window. The accepted settings are relative.
Parameters
Name | Type | Required | Description |
---|---|---|---|
top | number | Relative distance top coordinates. |
|
left | number | Relative distance left coordinates. |
onChannelsChangedmethod
Signature
(callback: (names: string[]) => void) => UnsubscribeFunction
Description
Notifies when the current Channels of the window have changed. Returns a function you can use to unsubscribe from the event.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (names: string[]) => void | Callback for handling the event. Receives the names of the current Channels as an argument. |
onContextUpdatedmethod
Signature
(callback: (context: any, window: WebWindow) => void) => UnsubscribeFunction
Description
Notifies when a change to the window's context has been made.
Parameters
Name | Type | Required | Description |
---|---|---|---|
callback | (context: any, window: WebWindow) => void | The function which will be invoked when a change to the window's context happens. The function will be called with the new context and window as arguments. |
onFocusChangedmethod
resizeTomethod
Signature
(width?: number, height?: number) => Promise<WebWindow>
Description
Sets a new size of the window. The accepted settings are relative.
Parameters
Name | Type | Required | Description |
---|---|---|---|
width | number | Relative width of the window. |
|
height | number | Relative height of the window. |
setContextmethod
Signature
(context: any) => Promise<WebWindow>
Description
Sets new context for the window.
Parameters
Name | Type | Required | Description |
---|---|---|---|
context | any | The new context object for the window. |
setTitlemethod
Signature
(title: string) => Promise<WebWindow>
Description
Sets a new title for the window
Parameters
Name | Type | Required | Description |
---|---|---|---|
title | string | The new title value. |
updateContextmethod
Signature
(context: any) => Promise<WebWindow>
Description
Updates the context object of the window
Parameters
Name | Type | Required | Description |
---|---|---|---|
context | any | The new context object for the window. |
RelativeDirectionenumeration
Description
- "top"
- "left"
- "right"
- "bottom"