--- url: "https://web.dev/articles/web-apps/shortcuts/pattern" titulek: "web.dev" h1: "" popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/web-apps/shortcuts/pattern" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:40:55" znaku: 2796 slov: 366 kodovani: "iso-8859-2" sha256: "a3f00b597eca1a4b7a42efa367a449a91a79ec199ee42a6554920ae6ea828cc9" --- Stay organized with collections Save and categorize content based on your preferences. HTML ` How to create app shortcuts

How to create app shortcuts

  1. You can drag these blue page or red page links to the bookmarks bar and access them later.
  2. Install the app by clicking the button below. After the installation, the button is disabled.

` JS `// The install button. const installButton = document.querySelector('button'); // Only relevant for browsers that support installation. if ('BeforeInstallPromptEvent' in window) { // Variable to stash the `BeforeInstallPromptEvent`. let installEvent = null; // Function that will be run when the app is installed. const onInstall = () => { // Disable the install button. installButton.disabled = true; // No longer needed. installEvent = null; }; window.addEventListener('beforeinstallprompt', (event) => { // Do not show the install prompt quite yet. event.preventDefault(); // Stash the `BeforeInstallPromptEvent` for later. installEvent = event; // Enable the install button. installButton.disabled = false; }); installButton.addEventListener('click', async () => { // If there is no stashed `BeforeInstallPromptEvent`, return. if (!installEvent) { return; } // Use the stashed `BeforeInstallPromptEvent` to prompt the user. installEvent.prompt(); const result = await installEvent.userChoice; // If the user installs the app, run `onInstall()`. if (result.outcome === 'accepted') { onInstall(); } }); // The user can decide to ignore the install button // and just use the browser prompt directly. In this case // likewise run `onInstall()`. window.addEventListener('appinstalled', () => { onInstall(); }); }` Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2026-07-29 UTC.