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
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.
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.
Create a new module called, for example, Extensions
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
});
}
});
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: