49 lines
1.5 KiB
HTML
49 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fr">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Ma PWA</title>
|
||
<link rel="manifest" href="manifest.json">
|
||
<link rel="stylesheet" href="styles/style.css">
|
||
<meta name="theme-color" content="#007bff">
|
||
</head>
|
||
<body>
|
||
<h1>Bienvenue sur ma PWA</h1>
|
||
<p>Cette application peut être installée comme une app mobile.</p>
|
||
|
||
<!-- Bouton d'installation -->
|
||
<button id="installBtn" hidden>📲 Installer l'application</button>
|
||
|
||
<script>
|
||
let deferredPrompt;
|
||
const installBtn = document.getElementById('installBtn');
|
||
|
||
window.addEventListener('beforeinstallprompt', (e) => {
|
||
e.preventDefault();
|
||
deferredPrompt = e;
|
||
installBtn.hidden = false;
|
||
|
||
installBtn.addEventListener('click', () => {
|
||
installBtn.hidden = true;
|
||
deferredPrompt.prompt();
|
||
|
||
deferredPrompt.userChoice.then((choiceResult) => {
|
||
if (choiceResult.outcome === 'accepted') {
|
||
console.log('L’utilisateur a accepté l’installation');
|
||
} else {
|
||
console.log('L’utilisateur a refusé l’installation');
|
||
}
|
||
deferredPrompt = null;
|
||
});
|
||
});
|
||
});
|
||
|
||
if ('serviceWorker' in navigator) {
|
||
navigator.serviceWorker.register('service-worker.js')
|
||
.then(() => console.log("Service worker enregistré"))
|
||
.catch(err => console.error("Erreur SW:", err));
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|