webview判断环境

264 阅读1分钟

安卓或者苹果环境判断

  const u = navigator.userAgent
  const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // android终端
  const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端

小程序或微信网页,wx怎么来的和涉及的微信网页授权点这里跳转

function checkWeChatEnvironment() {
    if (typeof wx !== 'undefined' && wx.miniprogram && wx.miniprogram.getEnv) {
        console.log('这是微信小程序');
    } else if (navigator.userAgent.toLowerCase().includes('micromessenger')) {
        console.log('这是微信网页');
    } else {
        console.log('不是微信网页也不是微信小程序');
    }
}
checkWeChatEnvironment();

小程序内部跳转、外部跳小程序内部

//小程序内部跳转
wx.miniProgram.navigateTo
//外部跳小程序内部
<wx-open-launch-weapp id="launch-btn" appid="xxxxxxx"
      path="pages/xxxxx">
   <template>
      <div>跳转到小程序</div>
   </template>
</wx-open-launch-weapp>