微信小程序跳转网页及网页如何返回小程序

第一步:小程序内单独新建page,在.wxml文件里,url就是跳转的路径,线上需要https,并且在公众平台配置了开发管理-》开发设置-》业务域名配置

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

.wxml
.js

第二步:从公众号网页中返回小程序,跳转成功后点击顶部的返回按钮ios无反应,需要在网页中处理,我这里用的是vue写的 需要引入jssdk

<template>

    <div></div>

</template>

<script>

export default {

  data() {

    return {

    }

  },

  mounted() {

      history.pushState(null, null, document.URL)

      // 点击小程序返回时会触发popstate事件

      window.addEventListener('popstate', this.handlePopstate)

  },

  beforeDestroy() {

    window.removeEventListener('popstate', this.handlePopstate)

  },

  methods: {

    handlePopstate(){

      // 返回到小程序

      wx.miniProgram.navigateBack({

        delta: history.length

      })

    }

  }

</script>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容