9

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.

4

3 回答 3

4

是的,现在您可以使用适用于 Android 的 Javascript 共享它。如果您需要更多详细信息或表示感谢,请点击链接

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'); 
});
于 2018-01-24T20:28:54.380 回答
1

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?

于 2013-11-12T18:36:52.453 回答
0

不是 jquery 本身,而是适用于 Android 的 Chrome 和 Android 的本机浏览器对此提供支持: https ://developer.chrome.com/multidevice/android/intents

不幸的是,文档非常有限,因为我试图弄清楚如何通过共享对话框共享链接(让用户可以选择与哪个应用程序共享链接)。

于 2015-11-13T07:13:33.767 回答