Skip to content

Instantly share code, notes, and snippets.

@adyontech
Created November 3, 2019 17:34
Show Gist options
  • Save adyontech/3b3ec8030f79bb0abed24f6f793314d8 to your computer and use it in GitHub Desktop.
Save adyontech/3b3ec8030f79bb0abed24f6f793314d8 to your computer and use it in GitHub Desktop.
(function () {
  'use strict';
  //Check if share API is supported or not
  if (navigator.share !== undefined) {
    document.addEventListener('DOMContentLoaded', function() {
      var shareBtn = document.querySelector('.share');
      //Share button event listener
      shareBtn.addEventListener('click', function(event) {
        //Web share API
        navigator.share({
          title: document.title,
          text: 'A simple pwa which works in offline, add to home screen and has a splash screen, push notifications, bg sync etc',
          url: window.location.href
        })
        .then(function() {
          console.info('Shared successfully.');
        })
        .catch(function (error) {
          console.error('Error in sharing: ', error);
        })
      });
    });
  }
})();
© 2019 GitH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment