Home  >  Article  >  Web Front-end  >  js获取微信版本号的方法_javascript技巧

js获取微信版本号的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 15:59:341805browse

微信现在几乎已经普遍在使用,但是微信版本一直在更新,不同的版本有不同的功能,于是了解微信的版本号很重要,以便自己及时更新体验新的功能。那么如何用js获取微信版本号呢?

一、判断微信版本号

var wechatInfo = navigator.userAgent.match(/MicroMessenger\\/([\\d\\.]+)/i) ;
if( !wechatInfo ) {
  alert("本活动仅支持微信") ;
} else if ( wechatInfo[1] < "5.0" ) {
  alert("本活动仅支持微信5.0以上版本") ;
}

其中 wechatInfo[1]  的值就是 版本号

二、js判断是否在微信浏览器中打开

function is_weixn(){
  var ua = navigator.userAgent.toLowerCase();
  if(ua.match(/MicroMessenger/i)=="micromessenger") {
    return true;
  } else {
    return false;
  }
}

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn