Is it possible to trigger share menu on smartphones (via HTML/JS)?

后端 未结 6 1190
半阙折子戏
半阙折子戏 2020-12-04 21:13

Is there an existing possibility to trigger the share functionality in local browsers on smartphones via HTML or JavaScript?

Of course there are many services which

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 22:05

    It is possible with a big catch. Currently only available in Chrome for Android and on Safari (desktop and mobile). http://caniuse.com/#feat=web-share

    if (navigator.share) {
      navigator.share({
        title: document.title,
        text: "Hello World",
        url: window.location.href
      }).then(() => console.log('Successful share'))
      .catch(error => console.log('Error sharing:', error));
    }
    

    https://developers.google.com/web/updates/2016/10/navigator-share

提交回复
热议问题