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 […]


This content originally appeared on Christian Heilmann and was authored by Chris 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:

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);
}

});

(yes, I do not use it here, because I want these share buttons to work without JS, but I will soon add this).


This content originally appeared on Christian Heilmann and was authored by Chris Heilmann


Print Share Comment Cite Upload Translate Updates
APA

Chris Heilmann | Sciencx (2024-11-16T11:43:36+00:00) What’s your excuse for not using the web share API?. Retrieved from https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/

MLA
" » What’s your excuse for not using the web share API?." Chris Heilmann | Sciencx - Saturday November 16, 2024, https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/
HARVARD
Chris Heilmann | Sciencx Saturday November 16, 2024 » What’s your excuse for not using the web share API?., viewed ,<https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/>
VANCOUVER
Chris Heilmann | Sciencx - » What’s your excuse for not using the web share API?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/
CHICAGO
" » What’s your excuse for not using the web share API?." Chris Heilmann | Sciencx - Accessed . https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/
IEEE
" » What’s your excuse for not using the web share API?." Chris Heilmann | Sciencx [Online]. Available: https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/. [Accessed: ]
rf:citation
» What’s your excuse for not using the web share API? | Chris Heilmann | Sciencx | https://www.scien.cx/2024/11/16/whats-your-excuse-for-not-using-the-web-share-api/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.