我正在尝试将横幅添加到主屏幕,我安装了 service-worker 和清单,尝试了这个但它没有显示横幅。这是我的代码:索引.php<!DOCTYPE html><html><head><title>Page Title</title><link rel="manifest" crossorigin="use-credentials" href="manifest.json"></head><body><h1>This is a Heading</h1><p>This is a paragraph.</p></body><script> if ('serviceWorker' in navigator) { console.log("Will the service worker register?"); navigator.serviceWorker.register('service-worker.js') .then(function(reg){ console.log("Yes, it did."); }).catch(function(err) { console.log("No it didn't. This happened:", err) }); }</script></html>清单文件{ "short_name": "BetaPage", "name": "BetaPage", "theme_color": "#4A90E2", "background_color": "#F7F8F9", "display": "standalone", "icons": [ { "src": "img/apple.png", "type": "image/png", "sizes": "48x48" }, { "src": "img/grapes.png", "type": "image/png", "sizes": "96x96" }, { "src": "img/lemon.png", "type": "image/png", "sizes": "144x144" }, { "src": "img/orange.png", "type": "image/png", "sizes": "192x192" } ], "start_url": "index.php" }service-worker.jsself.addEventListener('install', function(event) { console.log("installed");});self.addEventListener('activate', function(event) { // Perform some task console.log("activated"); });self.addEventListener('fetch', function(event) { console.log("fetched"); event.respondWith( fetch(event.request).catch(function() { return caches.match(event.request); }) ); });但仍然没有显示横幅,我的清单上没有错误。这是我的服务员我怎样才能解决这个问题?我目前正在我的本地主机上执行此操作。
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消