JavaScript Tips: Web share Api

Table of contents

const shareData = {
  title: "au.mirza",
  url: "https://www.instagram.com/au.mirza"
};

const btn = document.getElementById("share");
btn.addEventListener("click", shareHandler);

function shareHandler() {
  if (navigator.share && navigator.canShare(shareData)) {
    navigator
      .share(shareData)
      .then(alert("Thankyou for sharing."))
      .catch(webConsole);
  } else {
    webConsole(
      "Either your browser is incompatible or the data is not shareable"
    );
  }
}

Compatibility

Preview

This preview is taken from Edge running on Android 11.