The beforeinstallprompt
event fires on devices when a user is about to be prompted to "install" a web application. It may be saved for later and used to prompt the user at a more suitable time.
Window: beforeinstallprompt event
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('beforeinstallprompt', event => { }); onbeforeinstallprompt = event => { };
Event type
An BeforeInstallPromptEvent
. Inherits from Event
.
Event 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 choose between a web version or an Android version. -
BeforeInstallPromptEvent.userChoice
Read only -
Returns a
Promise
that resolves to aDOMString
containing either "accepted" or "dismissed".
Example
The following example uses the beforeinstallprompt
event to make an install button operable, by using the event inside a click handler.
window.addEventListener("beforeinstallprompt", function(beforeInstallPromptEvent) { beforeInstallPromptEvent.preventDefault(); // Prevents immediate prompt display // Shows prompt after a user clicks an "install" button installButton.addEventListener("click", function(mouseEvent) { // you should not use the MouseEvent here, obviously beforeInstallPromptEvent.prompt(); }); installButton.hidden = false; // Make button operable });
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
beforeinstallprompt_event |
61
44-61
The
onbeforeinstallprompt event handler property is not supported.
|
≤79
|
No
|
No
|
48
31-48
The
onbeforeinstallprompt event handler property is not supported.
|
No
|
61
44-61
The
onbeforeinstallprompt event handler property is not supported.
|
61
44-61
The
onbeforeinstallprompt event handler property is not supported.
|
No
|
45
32-45
The
onbeforeinstallprompt event handler property is not supported.
|
No
|
8.0
5.0-8.0
The
onbeforeinstallprompt event handler property is not supported.
|
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeinstallprompt_event