Course contentsShow
← Web Development
Lesson 2359 of 2,98242. Progressive Web AppsFree lesson

Hiding the Install Button After Installation

Detect when the app is successfully installed and hide the custom install button accordingly.

Hiding the Install Button After Installation

You'll learn how to detect a successful PWA installation and automatically hide your custom install button so users don't see it again.

Why This Matters

Once a user has installed your Progressive Web App, showing them the install button becomes unnecessary clutter. It's like keeping a "Download" button visible after someone has already downloaded and opened your app—confusing and unprofessional. The browser provides an event that fires when installation completes, letting you clean up your UI gracefully.

Detecting Installation

After the user accepts your install prompt (using the prompt() method on the beforeinstallprompt event object), the promise returns an object with a outcome property. However, even more reliably, the browser fires an appinstalled event on the window object when installation succeeds.

Listen for this event to perform cleanup:

// Hide the install button when app is successfully installed
window.addEventListener('appinstalled', (event) => {
  console.log('PWA was installed successfully');
  
  // Hide the custom install button
  const installButton = document.getElementById('install-button');
  installButton.style.display = 'none';
  
  // Optional: clear stored prompt event
  deferredPrompt = null;
});

This event fires after the user completes installation from the browser's install dialog, giving you a clear signal to update your interface. You might also store a flag in localStorage to remember the installed state across sessions, preventing the button from reappearing on future visits.

Think of it like a "mission accomplished" notification—once you receive it, you know the job is done and can remove the scaffolding.

Key Takeaway: Listen for the appinstalled event on window to detect successful installation, then hide your custom install button and clean up any stored state to provide a polished user experience.