知识分享
分享创造价值 合作实现共赢

知识分享

当前位置: 首页 > 知识分享

外部H5页面跳转 微信 ,跳转微信小程序

发布时间:2021-10-26 09:13:47作者:顺晟科技点击:

外部页面跳转微信 或者小程序 原理都是用Scheme

 

唤醒微信 最为简单

location.href = \'weixin://\';


唤醒小程序稍微复杂点,最近有个需求 是在H5落地页 唤醒小程序镶嵌的webview 页面,搭配微信云开发使用。  

async function test() {
var containerEl = document.getElementById(\'public-web-container\')
          containerEl.classList.remove(\'hidden\')
          containerEl.classList.add(\'full\', \'public-web-container\')
          var c = new cloud.Cloud({
            // 必填,表示是未登录模式
            identityless: true,
            // 小程序 AppID
            resourceAppid: \'小程序 AppID\', // <!-- replace -->
            // 云开发环境 ID
            resourceEnv: \'云开发环境 ID\', // <!-- replace -->
          })
          await c.init()
          window.c = c

          var buttonEl = document.getElementById(\'public-web-jump-button\')
          var buttonLoadingEl = document.getElementById(\'public-web-jump-button-loading\')
          try {
            await openWeapp(() => {
              buttonEl.classList.remove(\'weui-btn_loading\')
              buttonLoadingEl.classList.add(\'hidden\')
            })
          } catch (e) {
            buttonEl.classList.remove(\'weui-btn_loading\')
            buttonLoadingEl.classList.add(\'hidden\')
            throw e
          }

})
//生成Scheme 链接
async function openWeapp(onBeforeJump) { var c = window.c const res = await c.callFunction({ name: \'public\', data: { action: \'getUrlScheme\', }, }) console.warn(res) if (onBeforeJump) { onBeforeJump() } location.href = res.result.openlink }

 

TOP

QQ客服

18910140161