pwa制作

index.html

<html style="height: 100%">
 <head>
  <link rel="manifest" href="./manifest.json">
  <script src="service-worker.js"></script>
 </head>
 <body style="height: 100%; padding: 0; margin: 0">
<!-- <button type="button" id="aaa">aaaa</button>-->
<!-- <iframe src="http://localhost:8882/workflow/modeler/index.html#/processes"-->
<!--         width="100%" height="100%" frameborder="0"-->
<!-- ></iframe>-->
<!--  <div>Loading…</div>-->
  <script src="main.js"></script>
 </body>
</html>

main.js

// let deferredPrompt;
// let btnAdd = document.getElementById("aaa");
// window.addEventListener('beforeinstallprompt', (e) => {
//   // Prevent Chrome 67 and earlier from automatically showing the prompt
//   e.preventDefault();
//   // Stash the event so it can be triggered later.
//   deferredPrompt = e;
//   // Update UI to notify the user they can add to home screen
//   btnAdd.style.display = 'block';
// });
//
// btnAdd.addEventListener('click', (e) => {
//   window.location.href = 'https://chat.openai.com/chat'
//   // hide our user interface that shows our A2HS button
//   // btnAdd.style.display = 'none';
//   // // Show the prompt
//   // deferredPrompt.prompt();
//   // Wait for the user to respond to the prompt
//   // deferredPrompt.userChoice.then((choiceResult) => {
//   //   if (choiceResult.outcome === 'accepted') {
//   //     console.log('User accepted the A2HS prompt');
//   //     if (window.matchMedia('(display-mode: standalone)').matches) {
//   //       // ;
//   //     }
//   //   } else {
//   //     console.log('User dismissed the A2HS prompt');
//   //   }
//   //   deferredPrompt = null;
//   // });
// });

setTimeout(() => window.location.href="https://chat.openai.com/chat", 3000)

manifest.json

{

    "short_name": "ChatGPT",

    "name": "ChatGPT PWA",

    "start_url": "./index.html",

    "display": "standalone",

    "background_color": "#ffffff",

    "theme_color": "#ffffff",

    "icons": [

        {

            "src": "1.png",

            "sizes": "512x512",

            "type": "image/png"

        }

    ]

}

service-worker.js

if ('serviceWorker' in navigator) {
    navigator.serviceWorker
        .register('./service-worker.js')
        .then(function() { console.log('Service Worker Registered'); });
}

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值