I have the following in my PHP:
echo "<a id='share_button' class=''share_button href='#'>This will come in hand afterwards<a/>";
Then in my JavaScript code, I added this:
async function AndroidNativeShare(Title,URL,Description){
if(typeof navigator.share==='undefined' || !navigator.share){
alert('Your browser does not support Android Native Share, it\'s tested on chrome 63+');
} else if(window.location.protocol!='https:'){
alert('Android Native Share support only on Https:// protocol');
} else {
if(typeof URL==='undefined'){
URL = window.location.href;
}
if(typeof Title==='undefined'){
Title = document.title;
}
if(typeof Description==='undefined'){
Description = 'Share your thoughts about '+Title;
}
const TitleConst = Title;
const URLConst = URL;
const DescriptionConst = Description;
try{
await navigator.share({title:TitleConst, text:DescriptionConst, url:URLConst});
} catch (error) {
console.log('Error sharing: ' + error);
return;
}
}
}
jQuery(".share_button").click(function(BodyEvent){
var meta_desc,meta_title,meta_url
if(document.querySelector('meta[property="og:description"]')!=null) {
meta_desc = document.querySelector('meta[property="og:description"]').content;
}
if(document.querySelector('meta[property="og:title"]')!=null) {
meta_title = document.querySelector('meta[property="og:title"]').content;
}
if(document.querySelector('meta[property="og:meta_url"]')!=null) {
meta_url = document.querySelector('meta[property="og:meta_url"]').content;
}
AndroidNativeShare(meta_title, meta_url,meta_desc);
});