其他
Web Share API 成为 W3C 推荐标准
W3C Web 应用工作组发布
Web Share API 推荐标准:
W3C 推荐标准(W3C Recommendation)是基于广泛共识且获得 W3C 及其成员单位一致认可的技术规范,是 W3C 推荐广泛部署的 Web 标准,并依据《W3C 免版税专利政策》免费开放给公众使用。
navigator.share({title: 'Example Page', url: 'https://example.com'});
shareButton.addEventListener("click", async () => {
try {
await navigator.share({ title: "Example Page", url: "" });
console.log("Data was shared successfully");
} catch (err) {
console.error("Share failed:", err.message);
}
});
shareButton.addEventListener("click", async () => {
const file = new File(data, "some.png", { type: "image/png" });
try {
await navigator.share({
title: "Example File",
files: [file]
});
} catch (err) {
console.error("Share failed:", err.message);
}
});
const file = new File([], "some.png", { type: "image/png" });
// Check if files are supported
if (navigates.canShare({files: [file]})) {
// Sharing a png file would probably be ok...
}
// Check if a URL is ok to share...
if (navigates.canShare({ url: someURL })) {
// The URL is valid and can probably be shared...
}
const data = {
title: "Example Page",
url: "https://example.com",
text: "This is a text to share",
someFutureThing: "some future thing",
};
const allSupported = Object.entries(data).every(([key, value]) => {
return navigator.canShare({ [key]: value });
});
if (allSupported) {
await navigator.share(data);
}
const data = {
title: "Example Page",
url: "https://example.com",
text: "This is a text to share",
someFutureThing: "some future thing",
};
// Things that are not supported...
const unsupported = Object.entries(data).filter(([key, value]) => {
return !navigator.canShare({ [key]: value });
});
<iframe
src="https://third-party.example"
allow="web-share">
</iframe>
Permissions-Policy: web-share=()
https://www.w3.org/groups/wg/webapps