Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we invoke smart phone's native share functionality with jquery?

We can use phone's (android/ Iphones) native share functionality to share different content from apps. Is it also possible to invoke this share functionality through browser using javascript in all smart phones? So that on some event in browser, we can load share widget.

Thanks.

like image 526
sonam Avatar asked Nov 12 '13 12:11

sonam


2 Answers

Yes now you can share it with Javascript for Android. Follow link if you need more details or say thanks

https://sdtuts.com/javascript-android-native-share-popup-navigator-share-api/

async function AndroidNativeShare(Title,URL,Description){
  if(typeof navigator.share==='undefined' || !navigator.share){
    alert('Your browser does not support Android Native Share');
  } else {
    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;
    }   
  }
} 

$(".share_button").click(function(){
  AndroidNativeShare('My Page Title', 'https://google.com','This is description'); 
});
like image 62
r_4_1_n_l3_0_w Avatar answered Sep 20 '22 13:09

r_4_1_n_l3_0_w


For iOS/Android it is only possible if a UIWebView is opened within an app, but not from the native Safari/Chrome standalone browsers.

From in-app web view: How to Call Native Iphone/Android function from Javascript?

like image 23
Justin Avatar answered Sep 17 '22 13:09

Justin