javascriptandroidhtmliosshare

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


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 provide a share button. But when I e.g. want to share a website on facebook, I need to be logged in to facebook in the browser I am currently using.

Almost all browsers got an own share functionality build in, which triggers a system menu to choose which app you want to use to share:

System share menu in android os

This question is about: How to trigger this menu?

I know it is possible to trigger a phone call with a specified prefix in href attribute of links, like tel: or callto:. Maybe such a shortcut for this share menu is also existing? Or some javascript code? Or a totally different way how to do it?

Thanks in advance.


Solution

  • I added this as all answers seems outdated by 2018-07-16.

    It is possible, but only in a few browsers (MDN Reference), achieved througth the one method API in navigator:

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

    Google's reference: https://developers.google.com/web/updates/2016/10/navigator-share

    Also, there was a thing called Web Intends which is a dead project, you should go with navigator.share instead.