This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
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.
Syntax
ServiceWorkerClients.openWindow(url).then(function(WindowClient) { // do something with your WindowClient });
Parameters
url
- A
USVString
representing the URL of the client you want to open in the window. Generally this value must be a URL from the same origin as the calling script.
Return value
- A
Promise
that resolves to aWindowClient
object if the URL is from the same origin as the service worker or a null value otherwise.
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(clients) { for (i = 0; i < clients.length; i++) { if (clients[i].url === event.data.url) { // We already have a window to use, focus it. found = true; clients[i].focus(); break; } } if (!found) { // Create a new window. clients.openWindow(event.data.url).then(function(windowClient) { // do something with the windowClient. }); } }); };
Specifications
Specification | Status | Comment |
---|---|---|
Service Workers The definition of 'Clients' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 42.0[1] | 45.0 (45.0)[2] | No support | ? | No support |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | No support | No support | 45.0 (45.0) | (Yes) | No support | ? | No support | 40.0 [1] |
- [1] In Chrome 43 and later, you can open any URL. In Chrome 42 you could only open URLs on the same origin.
- [2] Service workers (and Push) have been disabled in the Firefox 45 Extended Support Release (ESR.)
Document Tags and Contributors
Tags:
Contributors to this page:
chrisdavidmills,
catalinb,
Rob W,
mar.castelluccio,
jpmedley,
Sebastianz,
kscarfone
Last updated by:
chrisdavidmills,