使用javascript添加到主屏幕功能

前端之家收集整理的这篇文章主要介绍了使用javascript添加到主屏幕功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我希望使用javascript按钮点击“添加到主屏幕”功能.我的第一个问题是.可以使用javascript或html / css吗?

我读过太多帖子但没找到任何正常工作的代码.我发现用户要做的就是转到chrome菜单和“添加到主屏幕”选项卡或chrome会提示用户并询问他们“添加到主屏幕”

最佳答案
下图显示文件资源管理器中的项目结构.公用文件夹中包含所有文件.并且清单文件位于公用文件

this is the image

之外

接下来创建Manifest.json和service-worker.js文件,如下所示:

的manifest.json

{
  "short_name": "BetaPage","name": "BetaPage","theme_color": "#4A90E2","background_color": "#F7F8F9","display": "standalone","icons": [
      {  
   "src": "assets/layouts/layout2/img/icon/android-icon-36x36.png","sizes": "36x36","type": "image/png","density": "0.75"
  },{
      "src": "assets/layouts/layout2/img/icon/android-icon-48x48.png","sizes": "48x48"
    },{
       "src": "assets/layouts/layout2/img/icon/android-icon-72x72.png","sizes": "72x72","density": "1.5"
  },{
    "src": "assets/layouts/layout2/img/icon/android-icon-96x96.png","sizes": "96x96","density": "2.0"
  },{
   "src": "assets/layouts/layout2/img/icon/android-icon-144x144.png","sizes": "144x144","density": "3.0"
  },{
   "src": "assets/layouts/layout2/img/icon/android-icon-192x192.png","sizes": "192x192","density": "4.0"
  }
  ],"start_url": "/index.html"
}

服务worker.js

self.addEventListener("fetch",function(event){

});

现在编辑index.html并在head部分添加以下代码

Meta name="msapplication-TileColor" content="#ffffff">
<Meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<Meta name="theme-color" content="#ffffff"> 

在同一个文件中,在关闭之前将代码放在下面

猜你在找的HTML相关文章