-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
42 lines (41 loc) · 1.59 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
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<head>
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/png" sizes="64x64" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/logo192.png">
<meta name="theme-color" content="#000000">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Title</title>
<meta name="description" content="This should be the description of your page. Try to keep it at 160 chars max.">
</head>
<body>
Check your console if the Service Worker is successfully registered.<br>
Fill in all the missing parameters and set the scope in "manifest.json" and add all your pages/files to "sw.js".<br><br>
Wait a few seconds (on Chrome mobile) and the "Add [Title] to Home screen" will appear.<br><br>
<input class="installButton" type="submit" value="Install PWA">
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('sw.js')
.then(function() {console.log("Service Worker Registered");});
}
let deferredPrompt;
const installButton = document.querySelector('.installButton');
installButton.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
//Add 'Install PWA' button to the page if the browser supports it.
if(deferredPrompt != undefined){
installButton.style.display = 'block';
installButton.addEventListener('click', (e) => {
deferredPrompt.prompt();
});
}
});
</script>
</body>
</html>