Logo

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
codepo8
Categories
3 categories in total
socialmedia
open
sharing
open
webstandards
open
Author
7 person written this
codepo8
open
What’s your excuse for not using the web share API?

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:

Animation of the web share API in action. With 10 lines of Code you can turn a button into a share button

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);
  }
});
Enter fullscreen mode Exit fullscreen mode

An empty url means the current document is shared. You can also add a different title, which makes more sense than "Example page".

sharing Article's
30 articles in total
Favicon
What’s your excuse for not using the web share API?
Favicon
Info card sharing service (free, no login required)
Favicon
Building a Tech Community from Scratch
Favicon
I Taught GIT to High School Students
Favicon
😮‍💨Saya Menyesal Beli Domain my.id
Favicon
<p *>Demystifying the Angular Structural Directives in a nutshell</p>
Favicon
Why I Like Writing Technical Blogs
Favicon
Add GitHub repository info, GitHub pages links and latest commits to any page using github-include
Favicon
Adding a "share to mastodon" link to any web site
Favicon
How do you differentiate Junior/Mid/Senior developer?
Favicon
Let anyone, anywhere, edit your static sites
Favicon
Digital Printing and Dev Printing: Are they the same?
Favicon
My “What is Coding?” Class
Favicon
Announcing Public Sharing: Share Your Drafts with the World on Contenda!
Favicon
sNationalDaysToday.com - Unite people to celebrate everyday
Favicon
Bugblogging
Favicon
The impact of sharing sessions in an engineering team
Favicon
Top 5 Things I Actually Like About Top {X} Posts
Favicon
Partnering with Google on web.dev
Favicon
Resource Helper website for easy access to daily usable links
Favicon
I make a list of free stuff/services for developers
Favicon
Sharing Local Server with Local Network (XAMPP)
Favicon
geek week local
Favicon
Adding RSS feed to my Nuxt & Storyblok blog
Favicon
What online image sharing service do you use?
Favicon
A Software to publish good code examples
Favicon
hackershare: Social bookmarking reinvented!
Favicon
Sharing keyboard & mouse across devices
Favicon
1 year experience, enjoying learning, but unfavorable atmosphere. Should I continue or not?
Favicon
Why I decided to start blogging and why we all should 🙌

Featured ones: