Jim Hare
Jim Hare

Reputation: 51

Web-apps: Can the iOS share sheet be triggered – and/or the shared URL customised – programatically?

Specifically, I would like to share granular page content via triggering the iOS share sheet with in-page buttons.

In my webapp page, I have a table of downloadable PDFs. I would like to be able to add a column called "Share" into the table, so that a button could be tapped to share the URL to that document, without having to open the document itself and share from there.

In order to do this, I assume I would need to customise this triggered share sheet to share a different URL to the one that is showing in mobile safari's address bar.

Is this possible using javascript, or alternative URLs in a meta tag maybe? I don't expect URL scheme to be a solution, as it is concerned with sending data to another application.

Upvotes: 5

Views: 11971

Answers (3)

DecisionNerd
DecisionNerd

Reputation: 1342

Yes, via the Web Share API

per the w3 docs:

shareButton.addEventListener("click", async () => {
  try {
    await navigator.share({ title: "Example Page", url: "" });
    console.log("Data was shared successfully");
  } catch (err) {
    console.error("Share failed:", err.message);
  }
});

Great article by Joe Medley on web.dev: Integrate with the OS sharing UI with the Web Share API

Upvotes: 0

ganar
ganar

Reputation: 691

Addendum 6/2020 It is possible since iOS 12.4, it works great.

It will be supported in Safari iOS V12.2. The beta of V12.2 already has it.

There's a good article by Maximiliano Firtman on a number of new features that will be possible in the new version.

Upvotes: 6

aWebDeveloper
aWebDeveloper

Reputation: 38392

Not currently on ios but a new w3c spec is on the way called web share api. Currently only available in chrome for android behind a origin trail.

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

Upvotes: 4

Related Questions