Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The BeforeInstallPromptEvent
is fired at the Window.onbeforeinstallprompt
handler before a user is prompted to "install" a web site to a home screen on mobile.
This interface inherits from the Event
interface.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 8.571428571428571%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-20 0 700 60" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent" target="_top"><rect x="1" y="1" width="240" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="121" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">BeforeInstallPromptEvent</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Constructor
BeforeInstallPromptEvent()
- Creates a new
BeforeInstallPromptEvent
.
Properties
Inherits properties from its parent, Event
.
BeforeInstallPromptEvent.platforms
Read only- Returns an array of
DOMString
items containing the platforms on which the event was dispatched. This is provided for user agents that want to present a choice of versions to the user such as, for example, "web" or "play" which would allow the user to chose between a web version or an Android version. BeforeInstallPromptEvent.userChoice
Read only- Returns a
Promise
that resolves to aDOMString
containing either 'installed' or 'dismissed'.
Methods
BeforeInstallPromptEvent.prompt()
- Allows a developer to show the install prompt at a time of their own choosing. This method returns a
Promise
.
Example
window.addEventListener("beforeinstallprompt", function(e) { // log the platforms provided as options in an install prompt console.log(e.platforms); // e.g., ["web", "android", "windows"] e.userChoice.then(function(outcome) { console.log(outcome); // either "installed", "dismissed", etc. }, handleError); });
Specifications
Specification | Status | Comment |
---|---|---|
Web App Manifest The definition of 'BeforeInstallPromptEvent' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 45 | No support | No support | No support | No support |
constructor | 45 | No support | No support | No support | No support |
platforms propety |
45 | No support | No support | No support | No support |
userChoice property |
45 | No support | No support | No support | No support |
prompt() method |
45 | No support | No support | No support | No support |
Feature | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 45 | 45 | No support | No support | No support | No support |
consructor | 45 | 45 | No support | No support | No support | No support |
platforms property |
45 | 45 | No support | No support | No support | No support |
userChoice property |
45 | 45 | No support | No support | No support | No support |
prompt() method |
45 | 45 | No support | No support | No support | No support |