Navigator.share API 向Pinterest分享时无法附带文本信息
我在ReactJS应用里使用navigator.share接口向Pinterest分享图片时,仅能保存图片,无法附带描述信息。桌面端通过URI模式可以实现图片和描述的同时保存,代码如下:
<a data-pin-do="buttonBookmark" data-pin-lang="en" href={`https://www.pinterest.com/pin/create/button/?url=${url}&medial=${imageUrl}&description=${desc}`} />
但移动端使用相同代码时,仍然只能保存图片。于是我尝试改用navigator.share接口,代码如下:
const handleNativeShare = async ({ title, url, image, text }) => { if (typeof window !== undefined) { if (typeof navigator !== undefined) { if (navigator.share) { const blob = await fetch(image).then((response) => response.blob()); let name=Date.now()+"-"+title+".png" let file = new File([blob], name, { type: blob.type, lastModified: Date.now() }); let shareData = { text, url, title, files: [file], }; navigator.share(shareData) .then(() => handleShare()) .catch((err) => console.log("Error sharing", err)); } else { alert("Share not supported by this browser") } } } }
结果移动端依旧只能保存图片,描述、标题或URL信息都无法附带,分享界面截图如下:

内容的提问来源于stack exchange,提问作者Nadir Hussain
相关产品推荐
相关产品推荐

