Clients.openWindow()

The openWindow() method of the Clients interface creates a new top level browsing context and loads a given URL. If the calling script doesn't have permission to show popups, openWindow() will throw an InvalidAccessError.

In Firefox, the method is allowed to show popups only when called as the result of a notification click event.

In Chrome for Android, the method may instead open the URL in an existing browsing context provided by a standalone web app previously added to the user's home screen.

Return value

Examples

// When the user clicks a notification focus the window if it exists or open
// a new one otherwise.
onotificationclick = function(event) {
var found = false;
clients.matchAll().then(function(clientsArr) {
for (i = 0; i < clientsArr.length; i++) {
if (clientsArr[i].url === event.data.url) {
// We already have a window to use, focus it.
found = true;
clientsArr[i].focus();
break;
}
}
if (!found) {
// Create a new window.
clients.openWindow(event.data.url).then(function(windowClient) {
// do something with the windowClient.
});
}
});
};