SHARING IS CARING!

Share Texts, URLs, or Files Using the Navigator Share API

A deep dive into the navigator share API with examples

Mehdi Namvar
5 min readApr 9, 2022

--

Have you ever wondered how can you open the native share dialog in web applications? I mean the share dialog that opens up on your iPhone or Android phone. I’m going to tell you how!

This is possible using the share() method on the navigator object. The navigator.share() method opens the native sharing dialog of the device to share data such as texts, URLs, or files.

As you can see, you can pass three properties. None of them are required but you need to pass at least one.

You should know that navigator.share() returns a Promise so it’s an async action and I’ll be using async/await syntax in my examples but feel free to use Promise if you’d like.

The share API is available only in secure contexts (HTTPS).

--

--