如何使用javascript通知用户访问网站的PWA应用程序

时间:2018-03-29 05:05:24

标签: javascript

我正在研究渐进式网络应用程序(PWA)并且有一些代码 - 工作正常。在这里,我想通知用户 - 访问网站有PWA​​并要求通过警告框安装PWA应用程序。如果用户单击“是”,则在设备上安装PWA。

我所关注的内容 - Youtube Udemy tutorial for PWA。我搜索了谷歌但没有找到任何内容

1 个答案:

答案 0 :(得分:0)

PWA默认特性是弹出并要求安装PWA,因此不需要警告框。如果配置服务工作者

if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('/sw.js').then(function(registration) {
      // Registration was successful
      console.log('ServiceWorker registration successful with scope: ', registration.scope);
    }, function(err) {
      // registration failed :(
      console.log('ServiceWorker registration failed: ', err);
    });
  });
}

  

的manifest.json

纠正它就足够了。 例如:

{
  "short_name": "AirHorner",
  "name": "Kinlan's AirHorner of Infamy",
  "icons": [
    {
      "src": "launcher-icon-1x.png",
      "type": "image/png",
      "sizes": "48x48"
    },
    {
      "src": "launcher-icon-2x.png",
      "type": "image/png",
      "sizes": "96x96"
    },
    {
      "src": "launcher-icon-4x.png",
      "type": "image/png",
      "sizes": "192x192"
    }
  ],
  "start_url": "index.html?launcher=true"
}

please refer the link