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.
window.addEventListener("beforeinstallprompt", function(event) { ... }); window.onbeforeinstallprompt = function(event) { ...};
The following example uses the beforeinstallprompt event handler to make an install button operable, by using the event inside a click handler.
window.addEventListener("beforeinstallprompt", function(e) { e.preventDefault(); // Prevents immediate prompt display // Shows prompt after a user clicks an "install" button installButton.addEventListener("click", function(e) { e.prompt(); }); installButton.hidden = false; // Make button operable });
Specification | Status | Comment |
---|---|---|
Web App Manifest The definition of 'Window.onbeforeinstallprompt' in that specification. | Working Draft | Initial specification. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | ? | ? | ? | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | ? | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/onbeforeinstallprompt