dev-resources.site
for different kinds of informations.
What’s your excuse for not using the web share API?
Published at
11/16/2024
Categories
socialmedia
sharing
webstandards
Author
Christian Heilmann
The WebShare API is so easy to use, it is a crime people don't use it more. Instead, we have tons of dead "share on $thing" buttons on the web. Many of which spy on your users and lots of them that started as Wordpress plugins but now are security concerns. Instead of guessing how your visitors want to share the current URL or a file you provide, you can call the API and they can pick their favourite:
This is the code and you can also check it on codepen:
let shareButton = document.querySelector('button');
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);
}
});
An empty url means the current document is shared. You can also add a different title, which makes more sense than "Example page".
Articles
12 articles in total
Learning HTML is the best investment I ever did
read article
trimMiddle() - the missing String trim method
read article
What’s your excuse for not using the web share API?
currently reading
httpstat.us is a great service to test your APIs and scripts
read article
Movie industry facts
read article
Quick tip: using flatMap() to extract data from a huge set without having to write a loop
read article
No more "Expert, Intermediate, Beginner": Classifying talks in Call for Papers/Conference agendas
read article
The best carb.js
read article
How we edited 175 conference videos in 5 hours
read article
Code puzzle - GSM-7 or UCS-2?
read article
Giving your app a temporary public URL with VS Code port forwarding
read article
10 print chr$(205.5 + rnd(1));:goto 10 in JavaScript
read article
Featured ones: