Skip to content
Related Articles
Open in App
Not now

Related Articles

How to use web share API for native share options in Html & JavaScript ?

Improve Article
Save Article
  • Last Updated : 15 Mar, 2021
Improve Article
Save Article

Web Share API is a JavaScript API that allows websites to share text/URL/file through device’s native share dialog by integrating with the OS. It works only with mobile devices and limited browsers. It was first introduced in Chrome 61 for android.

Features of web share API:

  • Capable of sharing URL, plain text or files.
  • Native, user-friendly and user-customized share dialogs.
  • Less code and OS managed UI. (Developer doesn’t need to handle dialog manually)
  • Wide range of sharing options. (Developer doesn’t have to worry about.)

Limitations of web share API:

  • Supported only on specific browsers and devices. (Advised to add a fallback to prevent compatibility issues)
  • Available only via HTTPS.
  • To prevent mishandling, It can be triggered only in response to some user action e.g. click

Note: Web share API is not supported on desktops and over non-HTTPS protocols. Hence, it is necessary to serve webpages over HTTPS in order to use it. 



<!DOCTYPE html>
        How to use web share API for native 
        share options in HTML and JavaScript?
<body style="text-align: center;">
    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>Web Share API Demonstration</h2>
    <button id="shareBtn">Share</button>
        .addEventListener('click', event => {
            // Fallback, Tries to use API only
            // if navigator.share function is
            // available
            if (navigator.share) {
                    // Title that occurs over
                    // web share dialog
                    title: 'GeeksForGeeks',
                    // URL to share
                    url: ''
                }).then(() => {
                    console.log('Thanks for sharing!');
                }).catch(err => {
                    // Handle errors, if occured
                    "Error while using Web share API:");
            } else {
                // Alerts user if API not available 
                alert("Browser doesn't support this API !");


This method is supported by many browsers that are listed below:

  • Chrome android (61+)
  • Firefox android (79+)
  • Opera android (48+)
  • iOS Safari (12.2+)
  • Samsung Internet (8.0+)


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!