Web Share API

Video

JavaScript Notes

HTML
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Web Share API</title>
        <meta name="viewport" content="width=device-width">
    </head>
    <body>
        <h1>Web Share API</h1>
        <h2>Available in Android Chrome version 61+</h2>
        <p></p>
        <script>
            // Available in Android Chrome version 61+
            // Uses Promises
            // Requires HTTPS
            // Requires a user interaction (like click)
            // As of version 61 of Android Chrome no longer required to sign up for Origin Trials
            // https://github.com/GoogleChrome/OriginTrials/blob/gh-pages/developer-guide.md
            // https://docs.google.com/forms/d/e/1FAIpQLSfO0_ptFl8r8G0UFhT0xhV17eabG-erUWBDiKSRDTqEZ_9ULQ/closedform
            
            document.addEventListener('click', () => {
                if( navigator.share !== undefined ){
                    let ttl = "Sample";
                    let txt = "I just shared from a web page.";
                    let url = "";
                    //use text and/or url
                    navigator.share( {title: ttl, text: txt} ) 
                        .then( _ => console.log('success.') )
                        .catch( (err) => console.log( err ) );
                }else{
                    document.querySelector('p').textContent = 'navigator.share is not supported';
                    console.log('navigator.share is not supported here.');
                }
            });
        </script>
    </body>
    </html>