我有一个从服务器生成的 pdf 文件,我希望允许用户通过 navigator.share 共享该文件。是否可以共享文件而不是 URL?
navigator.share({
title: 'Web Fundamentals',
text: 'Check out Web Fundamentals — it rocks!',
url: 'https://developers.google.com/web',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
Chrome 93.0.4570.0 现在支持通过 Web Share 共享 PDF 文件。看https://chromiumdash.appspot.com/commit/7d30d42a018d4aa76fca2896f2903d892b5f5284 https://chromiumdash.appspot.com/commit/7d30d42a018d4aa76fca2896f2903d892b5f5284 and https://bugs.chromium.org/p/chromium/issues/detail?id=1006055 https://bugs.chromium.org/p/chromium/issues/detail?id=1006055
shareButton.onclick = async () => {
const response = await fetch("https://example.com/files/hello.pdf");
const buffer = await response.arrayBuffer();
const pdf = new File([buffer], "hello.pdf", { type: "application/pdf" });
const files = [pdf];
// Share PDF file if supported.
if (navigator.canShare({ files })) await navigator.share({ files });
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)