在web-view中调用wx.miniProgram.navigateTo报undefined?
发布于 5 年前 作者 oxiao 1686 次浏览 来自 官方Issues
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js">
$scope.clickCloseWind = function () {
  function ready() {
  if(window.__wxjs_environment === 'miniprogram'){
	  wx.miniProgram.navigateTo({url: '/pages/mine/mine'})
  }else{
	   wx.closeWindow();
  }
}
if (!window.WeixinJSBridge || !WeixinJSBridge.invoke) {
  document.addEventListener('WeixinJSBridgeReady', ready, false)
} else {
  ready()
}

2 回复
   window.loadJs('https://res.wx.qq.com/open/js/jweixin-1.3.2.js',()=>{
       let ready = ()=>{
           if(window.__wxjs_environment === 'miniprogram'){
              window.wx.navigateTo({url: '/pages/mine/mine'})
            }
          }
      if (!window.WeixinJSBridge || !window.WeixinJSBridge.invoke) {
     document.addEventListener('WeixinJSBridgeReady', ready, false)
        } else {
      ready()
         }
     });
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == "micromessenger") {
  //ios的ua中无miniProgram,但都有MicroMessenger(表示是微信浏览器)
  wx.miniProgram.getEnv((res)=>{
    if (res.miniprogram) {
      console.log("小程序内跳转页面");
      wx.miniProgram.navigateTo({
        url: `/pages/webview/webview?url=${url}`
      });
     }
  });
} else {
  console.log("网页端跳转页面", url);
  window.location.href = url;
}
回到顶部