ऐप्लिकेशन शॉर्टकट बनाने का तरीका

François Beaufort
François Beaufort

ऐप्लिकेशन शॉर्टकट की मदद से, उपयोगकर्ता आपके वेब ऐप्लिकेशन में सामान्य या सुझाए गए टास्क तुरंत शुरू कर सकते हैं. ऐप्लिकेशन आइकॉन में कहीं से भी उन टास्क को आसानी से ऐक्सेस करने से, उपयोगकर्ताओं की उत्पादकता बढ़ेगी. साथ ही, वेब ऐप्लिकेशन के साथ उनका जुड़ाव भी बढ़ेगा.

आधुनिक तरीका

वेब ऐप्लिकेशन मेनिफ़ेस्ट में ऐप्लिकेशन शॉर्टकट तय करें

ऐप्लिकेशन शॉर्टकट मेन्यू बनाने के लिए, उपयोगकर्ता के डेस्कटॉप पर टास्कबार (Windows) या डॉक (macOS) में मौजूद ऐप्लिकेशन आइकॉन पर राइट क्लिक करें. इसके अलावा, Android पर ऐप्लिकेशन के लॉन्चर आइकॉन को दबाकर रखें.

Android डिवाइस पर ऐप्लिकेशन शॉर्टकट मेन्यू खुला है.
Android पर ऐप्लिकेशन शॉर्टकट मेन्यू खोला गया
Windows पर ऐप्लिकेशन शॉर्टकट मेन्यू खोला गया है.
Windows पर ऐप्लिकेशन शॉर्टकट मेन्यू खोला गया

ऐप्लिकेशन शॉर्टकट मेन्यू सिर्फ़ उन प्रोग्रेसिव वेब ऐप्लिकेशन के लिए दिखता है जो इंस्टॉल किए गए हैं. इंस्टॉल करने की ज़रूरी शर्तों के बारे में जानने के लिए, PWA के बारे में जानें मॉड्यूल में, इंस्टॉल करने की सुविधा देखें.

हर ऐप्लिकेशन शॉर्टकट, उपयोगकर्ता के मकसद के बारे में बताता है. इनमें से हर एक शॉर्टकट, आपके वेब ऐप्लिकेशन के दायरे में आने वाले यूआरएल से जुड़ा होता है. जब कोई उपयोगकर्ता ऐप्लिकेशन शॉर्टकट को चालू करता है, तब यूआरएल खुलता है.

ऐप्लिकेशन शॉर्टकट का एलान, वेब ऐप्लिकेशन मेनिफ़ेस्ट के shortcuts कलेक्शन में वैकल्पिक तौर पर किया जाता है. नीचे संभावित वेब ऐप्लिकेशन मेनिफ़ेस्ट का एक उदाहरण दिया गया है.

{
  "name": "Player FM",
  "start_url": "https://player.fm?utm_source=homescreen",
  "shortcuts": [
    {
      "name": "Open Play Later",
      "short_name": "Play Later",
      "description": "View the list of podcasts you saved for later",
      "url": "/play-later?utm_source=homescreen",
      "icons": [{ "src": "/icons/play-later.png", "sizes": "192x192" }]
    },
    {
      "name": "View Subscriptions",
      "short_name": "Subscriptions",
      "description": "View the list of podcasts you listen to",
      "url": "/subscriptions?utm_source=homescreen",
      "icons": [{ "src": "/icons/subscriptions.png", "sizes": "192x192" }]
    }
  ]
}

ब्राउज़र सहायता

  • 96
  • 96
  • x
  • 78 जीबी में से

सोर्स

क्लासिक तरीका

अगर ऐप्लिकेशन अभी तक इंस्टॉल नहीं किया गया है, तो उपयोगकर्ता को अपने वेब पेज से कुछ लिंक खींचने और उन्हें ब्राउज़र के बुकमार्क बार में छोड़ने का सुझाव दिया जा सकता है. इस तरह, वे आपके वेब ऐप्लिकेशन में सामान्य या सुझाए गए टास्क तेज़ी से शुरू कर सकते हैं.

इसके बारे में और पढ़ें

डेमो

एचटीएमएल

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="color-scheme" content="dark light" />
    <link rel="manifest" href="manifest.json" />
    <title>How to create app shortcuts</title>
    <!-- TODO: Devsite - Removed inline handlers -->
    <!-- <script>
      if ('serviceWorker' in navigator) {
        window.addEventListener('load', () => {
          navigator.serviceWorker.register('sw.js');
        });
      }
    </script>
    <script type="module" src="script.js"></script> -->
  </head>
  <body>
    <h1>How to create app shortcuts</h1>
    <ol>
      <li>
        You can drag these <a href="blue.html">blue page</a> or
        <a href="red.html">red page</a> links to the bookmarks bar
        and access them later.
      </li>
      <li>
        Install the app by clicking the button below. After the installation,
        the button is disabled.
        <p>
          <button disabled type="button">Install</button>
        </p>
      </li>
    </ol>
  </body>
</html>

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();
  });
}