Skip to content

Instantly share code, notes, and snippets.

@charisTheo
Created October 15, 2019 15:21
Show Gist options
  • Save charisTheo/f38dacb5e6884c7c17c8c4295c85cbb6 to your computer and use it in GitHub Desktop.
Save charisTheo/f38dacb5e6884c7c17c8c4295c85cbb6 to your computer and use it in GitHub Desktop.
A button click event listener for opening the Web Share API natively on mobile web
function shareButtonClickListener(event) {
if (navigator.share) {
navigator.share({
title: 'CharisTheo',
text: 'Look at this wonderful website!',
url: 'https://www.wonderful.website',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
} else {
// Web Share API not found!
// copy link to clipboard
copyToClipboard('https://www.wonderful.website');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment