Skip to content

Instantly share code, notes, and snippets.

@camaleaun
Created May 29, 2020 14:16
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 camaleaun/209fb1aa732e2bc794f68531f4bc5266 to your computer and use it in GitHub Desktop.
Save camaleaun/209fb1aa732e2bc794f68531f4bc5266 to your computer and use it in GitHub Desktop.
Native sharing
window.addEventListener( 'load', () => {
document.querySelectorAll( '.sharing-anchor' ).forEach( ( anchor ) => {
anchor.addEventListener( 'click', () => {
if ( undefined !== navigator.share ) {
navigator.share( {
title: document.querySelector( 'meta[property="og:title"]' ).content,
text: document.querySelector( 'meta[property="og:description"]' ).content,
url: document.querySelector( 'meta[property="og:url"]' ).content,
} )
}
} );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment