分享好友 教程首页 教程搜索 频道列表

在小程序内点击按钮分享H5网页给好友或者朋友圈

2021-08-16 11:1110520
+关注28
核心提示:首先需要建立h5容器文件夹页面

首先需要建立h5容器文件夹


页面.wxml

<navigator url="/pages/report-await/fouryearh5share/fouryearh5share">
  <button  class="sharebutton"  open-type="share" ></button >
</navigator>


页面.js

onShareAppMessage: function (res) {
var that = this
  if (res.from === 'button') {
    // 来自页面内转发按钮
    console.log(res.target)
  }
  return {
title: '我们陪你一起到家!',
//这一点很重要哦,小程序只能打开自己的页面,所以需要本地的地址+webViewUrl的地址才行。
path: "/pages/report-await/fouryearh5share/fouryearh5share?url=" + res.webViewUrl,
imageUrl: 'https://lbdj.oss-cn-beijing.aliyuncs.com/pc/img/activity/xxx/share.png',
    success: (res) => {
      if (res.data.code == 0) {
        wx.showToast({
        title: '发送邀请好友成功',
        icon: 'success',
        duration: 2000
      })
    } else {
     wx.showToast({
      title: res.data.message,
      icon: 'none',
      duration: 2000
    })
   }
  },
    fail: (res) => {
    console.log("转发失败", res);
    }
  }
}


h5容器.wxml (注意删掉 src 后的空格)

<web-view src ="{{shareUrl}}"></web-view>


h5容器.js

data: {
shareUrl: null
},  onLoad: function (options) {
  var that = this
  that.setData({
shareUrl: "http://xxx.com/fourYear"
  })
}


TIPS: 操作要有一定的小程序开发技术

本文标签: #小程序 #封装 #h5 #分享 #朋友圈
整理员:网络
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
您可能在找更多

关于小程序独立认证那些事

网络转载 随手记2024-03-03

DESTOON9.0以下的版本如何修复电脑版微信小程序跳转到电脑版

    按照9.0的代码去修改

小黑 destoon程序2023-04-13

如何生成背景透明的微信小程序二维码

    如何生成背景透明的微信小程序二维码透明背景参数is_hyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码

网络转载 开发技术2023-04-13

微信小程序如何关闭云开发

网络转载 小程序2022-09-16

下一篇
我来说两句
抢沙发