理想是火,点燃熄灭的灯。
直接上代码吧:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <p><button>Share MDN!</button></p> <p class="result"></p> </body> <script> const btn = document.querySelector("button"); const resultPara = document.querySelector(".result"); const shareData = { title: "MDN", text: "Learn web development on MDN!", url: "https://developer.mozilla.org", }; btn.addEventListener("click", () => { navigator .share(shareData) .then(() => (resultPara.textContent = "MDN shared successfully")) .catch((e) => (resultPara.textContent = "Error: " + e)); }); </script> </html>
注:可能存在浏览器兼容的问题,暂时只在chrome上使用。
MDN WEB DOC 参考文档:https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
作者: Bill 本文地址: http://biaoblog.cn/info?id=1618818840000
版权声明: 本文为原创文章,版权归 biaoblog 个人博客 所有,欢迎分享本文,转载请保留出处,谢谢!