我希望使用javascript按钮点击“添加到主屏幕”功能.我的第一个问题是.可以使用javascript或html / css吗?
我读过太多帖子但没找到任何正常工作的代码.我发现用户要做的就是转到chrome菜单和“添加到主屏幕”选项卡或chrome会提示用户并询问他们“添加到主屏幕”
最佳答案
下图显示了文件资源管理器中的项目结构.公用文件夹中包含所有文件.并且清单文件位于公用文件夹之外
原文链接:https://www.f2er.com/html/426600.html接下来创建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){
});
Meta name="msapplication-TileColor" content="#ffffff">
<Meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<Meta name="theme-color" content="#ffffff">
现在运行您的项目,等待几分钟并重新加载您的页面.
请享用 !