How do you call in xojo SHARES

hello!
i am in a webapp developing, and as such, it can be used in a phone o tablet from the browser. I am in need to call a SHARE TO… with a single button, can anyone help me? can it be call with a javascript code?

It seems to be that it is a call such as Navigator.share() from the site

regards.

jan 22 to jun 23… nobody has done a button that calls the browser function share?

The xojo web comunity is tiny, almost zero chances of someone doing this.

As for the original question, looks like the Share API needs to be fired by a direct user interaction. xojo dont have client side actions, instead, when the user interact with an object, it fires an event, makes a round trip to the server and then some code executes the action in the browser.

Maybe the only way is with a custom control with the web sdk. :thinking:

Web Share API is barely supported by browsers. If the browser supports it, the page will still need to be served via HTTPS and the API will be only accessible as a direct response of a user action, browser-side.

Here is an example using a button extension.

  1. Create a new module called, for example, Extensions
  2. Add a new constant inside, called kShareAPIJavaScript with this content:
const el = document.getElementById('%ControlID%');
el.addEventListener('pointerup', function(ev) {
  if (navigator.share) {
    navigator.share({
      title: document.title, // Feel free to change this to something else
      url: location.href, // Feel free to change this to something else
    });
  }
});
  1. Add a new method inside the module, EnableShareAPI:
Public Sub EnableShareAPI(Extends button As WebButton)
  Var js As String = kShareAPIJavaScript.Replace("%ControlID%", button.ControlID)
  button.ExecuteJavaScript(js)
End Sub

Now you can use it in any WebButton. For example, drop a new button into a WebPage and, inside the Opening event, call the new method:

Me.EnableShareAPI

The result with an Android emulator using Chrome:

web-share

3 Likes

Here’s what Ricardo means by “barely supported”

Looks like iOS was first, but Android and others have been slow on the uptake.

It looks like it’s still just a “recommendation” as of May-30.

1 Like

thanks Ricardo!!!

1 Like