2021-02-02微信小程式 web-view 和 小程式頁面互動
阿新 • • 發佈:2021-02-03
微信小程式 web-view 和 小程式頁面可以交換資訊。
比如,web-view頁面 可以 返回微信小程式頁面。
在test.html頁面中這樣寫
<body>
<button onclick="reLaunch()">跳轉到 f 頁面</button>
<button onclick="navigateTo()">navigateTo到 register頁面</button>
</body>
js 中這樣寫
<script type= "text/javascript">
function navigateTo(){
wx.miniProgram.navigateTo({
url:'/page/login', //指定跳轉至小程式頁面的路徑
success: function(){
console.log('success'); //頁面跳轉成功的回撥函式
}
});
};
function reLaunch(){
wx.miniProgram.reLaunch({
url:'/login'
})
alert ("執行跳轉");
};
</script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js">
</script>
在小程式中這樣寫
<web-view src="https://******.cn/test.html#wechat_redirect">
就可以跳轉成功了,如果失敗,那很可能是路徑出了問題。
還有 不要忘了 引入 微信的 js檔案。