Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: Event
Source: JSObjects/BeforeInstallPromptEvent.cs
MDN Reference: BeforeInstallPromptEvent on MDN
The BeforeInstallPromptEvent is the interface of the beforeinstallprompt event fired at the Window object before a user is prompted to "install" a website to a home screen on mobile. https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent Experimental: This is an experimental technology. Check the Browser compatibility table (MDN) carefully before using this in production.
| Signature | Description |
|---|---|
BeforeInstallPromptEvent(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Property | Type | Access | Description |
|---|---|---|---|
Platforms |
string[] |
get | Returns an array of string 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. |
UserChoice |
Task<InstallPromptResult> |
get | Returns a Promise that resolves to an object describing the user's choice when they were prompted to install the app. |
| Method | Return Type | Description |
|---|---|---|
Prompt() |
Task<InstallPromptResult> |
Show a prompt asking the user if they want to install the app. This method returns a Promise that resolves to an object describing the user's choice when they were prompted to install the app. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<BeforeInstallPromptEvent>(...)or constructornew BeforeInstallPromptEvent(...)
let installPrompt = null;
const installButton = document.querySelector("#install");
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
installPrompt = event;
installButton.removeAttribute("hidden");
});installButton.addEventListener("click", async () => {
if (!installPrompt) {
return;
}
const result = await installPrompt.prompt();
console.log(`Install prompt was: ${result.outcome}`);
installPrompt = null;
installButton.setAttribute("hidden", "");
});