Skip to content

Instantly share code, notes, and snippets.

@alechash
Created March 13, 2021 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alechash/2c634d9c0775045c742c789e23650100 to your computer and use it in GitHub Desktop.
Save alechash/2c634d9c0775045c742c789e23650100 to your computer and use it in GitHub Desktop.
javascript enabled navigator share
<style>
.hidden {
display: none;
}
</style>
<button id="_share" class="hidden">share</button>
<script>
if (navigator.share) {
document.getElementById('_share').classList.remove('hidden');
document.getElementById('_share').addEventListener('click', function() {
navigator.share({
title: 'title',
text: 'message',
url: 'https://some.url'
});
return false;
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment