The Window.onbeforeinstallprompt
property is an event handler for processing a beforeinstallprompt
, which is dispatched on devices when a user is about to be prompted to "install" a web application. Its associated event may be saved for later and used to prompt the user at a more suitable time.
Syntax
window.addEventListener("beforeinstallprompt", function(event) { ... }); window.onbeforeinstallprompt = function(event) { ...};
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
No support No |
IE
? |
Opera
Full support Yes |
Safari
? |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
No support No |
Opera Android
Full support Yes |
Safari iOS
? |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Non-standard. Expect poor cross-browser support.'
- Non-standard. Expect poor cross-browser support.
See Also
Window.onbeforeinstallprompt by Mozilla Contributors is licensed under CC-BY-SA 2.5.