Yes, you can share on desktop. Maybe.

A quick demonstration of making a share button - even on desktops!

Yes, you can share on desktop. Maybe.

Here's some quick test code in response to this forum post, trying to see if we can easily make a sharing button appear or disappear depending on available functionality. Yes, we can. But you might have this functionality on your desktop anyway, so if you see the button, you should click it! :)


Here's the code!

<p id="yo">Hello!</p>
<button id="mybutton">let's share!</button>
    if (navigator.canShare) {document.getElementById('yo').innerHTML = "yes, you can share!"
                               document.querySelector('#mybutton').addEventListener('click', processclick)

    } else { document.getElementById('yo').innerHTML="nope, your device cannot share" ; document.getElementById('mybutton').remove()}

function processclick () { 
  console.log('button pressed')
  navigator.share({title:"test title", url: ""})