💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 概述 提供了一种将文本、链接、文件和其他内容共享到用户选择的任意*共享目标*的机制 **语法** ``` interface ShareData { text?: string; title?: string; url?: string; } ``` ## 示例 ``` const shareData = { title: 'MDN', text: 'Learn web development on MDN!', url: 'https://developer.mozilla.org' } const btn = document.querySelector('button'); const resultPara = document.querySelector('.result'); // Share must be triggered by "user activation" btn.addEventListener('click', async () => { try { await navigator.share(shareData) resultPara.textContent = 'MDN shared successfully' } catch(err) { resultPara.textContent = 'Error: ' + err } }); ``` 效果 ![](https://img.kancloud.cn/90/e5/90e5763a90bc40e71d8a7e257f6de90a_453x663.png)