做法
新增 index.html 檔。
| 12
 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
 
 | <!DOCTYPE html><html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 </head>
 <body>
 <button onclick="share()">Share</button>
 <script>
 const share = async () => {
 if (navigator.share) {
 try {
 await navigator.share({
 title: document.title,
 text: 'Hello, World!',
 url: window.location.href,
 });
 } catch (err) {
 console.error(err);
 }
 }
 };
 </script>
 </body>
 </html>
 
 | 
啟動伺服器。
使用 ngrok 指令,啟動一個 HTTP 代理伺服器,將本地埠映射到外部網址。
使用手機複製結果如下:
參考資料