files/en-us/web/api/beforeinstallpromptevent/index.md
{{APIRef}}{{SeeCompatTable}}{{Non-standard_header}}
The BeforeInstallPromptEvent is the interface of the {{domxref("Window.beforeinstallprompt_event", "beforeinstallprompt")}} event fired at the {{domxref("Window")}} object before a user is prompted to "install" a website to a home screen on mobile.
This interface inherits from the {{domxref("Event")}} interface.
{{InheritanceDiagram}}
BeforeInstallPromptEvent object.Inherits properties from its parent, {{domxref("Event")}}.
In the following example an app provides its own install button, which has an id of "install". Initially the button is hidden.
<button id="install" hidden>Install</button>
The beforeinstallprompt handler:
BeforeInstallPromptEvent object to a variable, so it can be used laterlet installPrompt = null;
const installButton = document.querySelector("#install");
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
installPrompt = event;
installButton.removeAttribute("hidden");
});
When clicked, the app's install button:
installPrompt variable and hiding itself again.installButton.addEventListener("click", async () => {
if (!installPrompt) {
return;
}
const result = await installPrompt.prompt();
console.log(`Install prompt was: ${result.outcome}`);
installPrompt = null;
installButton.setAttribute("hidden", "");
});
{{Compat}}