79407729

Date: 2025-02-03 03:12:07
Score: 3.5
Natty:
Report link

It work's just fine for me: https://shotor.github.io/web-share-api/

Make sure you run it in a browser that supports it: https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#api.navigator.share

In my case, it doesn't work on desktop chrome/firefox. But works fine on android chrome.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Web Share API</title>
  </head>
  <body>
    <button
      class="share-button"
      data-share-title="Web Share API @ MDN"
      data-share-url="https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API"
    >
      Share MDN
    </button>

    <button
      class="share-button"
      data-share-title="Web Share API @ Google"
      data-share-url="https://web.dev/web-share/"
    >
      Share Google
    </button>

    <script>
      document.querySelectorAll('.share-button').forEach((button) => {
        button.addEventListener('click', async () => {
          const title = button.getAttribute('data-share-title')
          const url = button.getAttribute('data-share-url')

          if (navigator.share) {
            await navigator.share({
              title,
              url,
            })
            console.log('Thanks for sharing!')
            return
          }

          const shareUrl = `https://twitter.com/share?url=${encodeURIComponent(
            url
          )}`
          window.open(shareUrl, '_blank')
        })
      })
    </script>
  </body>
</html>
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (2): Thanks for sharing
  • Probably link only (1):
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: shotor