share.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  6. <meta name="HandheldFriendly" content="true"/>
  7. <meta name="MobileOptimized" content="320"/>
  8. <title>Hello H5+</title>
  9. <script type="text/javascript" src="../js/common.js"></script>
  10. <script type="text/javascript">
  11. var shares=null;
  12. // H5 plus事件处理
  13. function plusReady(){
  14. // 延时获取服务列表,避免影响窗口动画
  15. setTimeout(updateSerivces, 500);
  16. }
  17. if(window.plus){
  18. plusReady();
  19. }else{
  20. document.addEventListener('plusready', plusReady, false);
  21. }
  22. /**
  23. * 更新分享服务
  24. */
  25. function updateSerivces(){
  26. plus.share.getServices(function(s){
  27. shares={};
  28. for(var i in s){
  29. var t=s[i];
  30. shares[t.id]=t;
  31. }
  32. }, function(e){
  33. outSet('获取分享服务列表失败:'+e.message);
  34. });
  35. }
  36. /**
  37. * 调用系统分享
  38. */
  39. function shareSystem(){
  40. outSet('调用系统分享');
  41. var msg={content:sharecontent.value};
  42. if('iOS'==plus.os.name){//iOS平台添加链接地址
  43. msg.href='http://www.dcloud.io/';
  44. }
  45. outLine(JSON.stringify(msg));
  46. plus.share.sendWithSystem?plus.share.sendWithSystem(msg, function(){
  47. outLine('Success');
  48. console.log('Success');
  49. }, function(e){
  50. outLine('Failed: '+JSON.stringify(e));
  51. console.log('Failed: '+JSON.stringify(e));
  52. }):shareSystemNativeJS();
  53. }
  54. function shareSystemNativeJS() {
  55. if(plus.os.name!=='Android'){
  56. plus.nativeUI.alert('此平台暂不支持系统分享功能!');
  57. return;
  58. }
  59. var intent=new Intent(Intent.ACTION_SEND);
  60. intent.setType('text/plain');
  61. intent.putExtra(Intent.EXTRA_SUBJECT,'HelloH5');
  62. intent.putExtra(Intent.EXTRA_TEXT,sharecontent.value);
  63. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  64. main.startActivity(Intent.createChooser(intent,'系统分享HelloH5'));
  65. }
  66. // 调用小程序
  67. function launchMiniProgram(){
  68. if(!shares['weixin']){
  69. plus.nativeUI.toast('未配置微信分享模块!');
  70. return;
  71. }
  72. shares['weixin'].launchMiniProgram({
  73. id: 'gh_33446d7f7a26', // 小程序原始ID
  74. type: 0 // 正式版
  75. });
  76. }
  77. </script>
  78. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
  79. <style type="text/css">
  80. #sharecontent{
  81. width:80%;
  82. -webkit-user-select:text;
  83. border: 1px solid #6C6C6C;
  84. -webkit-border-radius: 2px;
  85. border-radius: 2px;
  86. }
  87. #pic{
  88. width:100px;
  89. height:100px;
  90. /*border: 1px dashed #CCCCCC;*/
  91. }
  92. .sharehref{
  93. width:80%;
  94. -webkit-user-select:text;
  95. border: 1px solid #6C6C6C;
  96. -webkit-border-radius: 2px;
  97. border-radius: 2px;
  98. margin-bottom: .5em;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <br/>
  104. <div class="button" onclick="clicked('share_weixin.html')">微信分享</div>
  105. <div class="button" onclick="clicked('share_qq.html')">QQ分享</div>
  106. <div class="button" onclick="clicked('share_sinaweibo.html')">微博分享</div>
  107. <br/>
  108. <hr color="#EEE"/>
  109. <br/>
  110. <p class="heading">分享内容:</p>
  111. <textarea id="sharecontent" rows="3">我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!</textarea>
  112. <br/><br/>
  113. <div class="button" onclick="shareSystem()">系统分享</div>
  114. <br/>
  115. <hr color="#EEE"/>
  116. <br/>
  117. <p class="heading">需在微信开放平台将应用关联小程序才能正常调用</p>
  118. <div class="button" onclick="launchMiniProgram()">调用微信小程序</div>
  119. <div id="outpos"/>
  120. <div id="output">
  121. Share模块管理客户端的社交分享功能,提供调用终端社交软件的分享能力。通过plus.share可获取社交分享管理对象。
  122. </div>
  123. </body>
  124. </html>