-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
80 lines (70 loc) · 1.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="" />
<meta name="og:description" content="pwa" />
<meta property="og:video:width" content="385" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pwa-template</title>
<link rel="manifest" href="./manifest.json" />
</head>
<style>
body {
height: 100vh;
display: flex;
font-family: sans-serif;
justify-content: center;
align-items: center;
background-color: white;
}
.container {
display: flex;
flex-direction: column;
background-color: white;
justify-content: space-around;
height: 800px;
width: 400px;
}
</style>
<body>
<script>
window.addEventListener("load", () => {
registerSW();
});
//popup to prompt install
let deferredPrompt;
window.addEventListener("beforeinstallprompt", (e) => {
deferredPrompt = e;
});
//logic for install buttonInstall
const installApp = document.getElementById("installApp");
installApp.addEventListener("click", async () => {
if (deferredPrompt !== null) {
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
if (outcome === "accepted") {
deferredPrompt = null;
}
}
});
//logic for install buttonInstall
</script>
<div class="container">
<center><h1>Pwa Template</h1></center>
<center><p>Made with 💖 by Langat Fortune</p></center>
</div>
<script>
async function registerSW() {
if ("serviceWorker" in navigator) {
try {
await navigator.serviceWorker.register("./sw.js");
} catch (e) {
console.log(`SW registration failed`);
}
}
}
</script>
</body>
</html>