h5網頁跳轉到小程序


第一:網頁引用

<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>


第二步 判斷當前環境

//判斷當前頁面是否在小程序環境中, 注:首頁是在小程序,嵌套網頁,該網頁才能再次跳轉回小程序
wx.miniProgram.getEnv(function(res) {
console.log(res.miniprogram) // true
if(res.miniprogram){
smallPro=true;
}else{
smallPro=false;
}
});
if(smallPro){ //小程序環境
     wx.miniProgram.navigateTo({
    url:'/pages/index/index?id=1',//跳轉回小程序的頁面,傳參id, 小程序onLoad函數接收參數即可
    success: function(){
    console.log('success')
   },
    fail: function(){
    console.log('跳轉回小程序的頁面fail');
   },
   });
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM