Skip to content

Instantly share code, notes, and snippets.

@vinplezhang
Forked from GiaoGiaoCat/wechat-useragent.js
Created September 11, 2017 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinplezhang/0695f1f3aa950db7d9f05d6495054fbe to your computer and use it in GitHub Desktop.
Save vinplezhang/0695f1f3aa950db7d9f05d6495054fbe to your computer and use it in GitHub Desktop.
微信内置浏览器UserAgent的判断
// 检测浏览器的 User Agent 应该是非常简单的事情
// 微信在 Android 下的 User Agent
mozilla/5.0 (linux; u; android 4.1.2; zh-cn; mi-one plus build/jzo54k) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30 micromessenger/5.0.1.352
// 微信在 iPhone 下的 User Agent
mozilla/5.0 (iphone; cpu iphone os 5_1_1 like mac os x) applewebkit/534.46 (khtml, like gecko) mobile/9b206 micromessenger/5.0
// 通过javascript判断
// 很容易看出来,微信的 User Agent 都有‘micromessenger’字符串标示,我们判断是否含有这些字符串就OK了
function isWeixinBrowser(){
var ua = navigator.userAgent.toLowerCase();
return (/micromessenger/.test(ua)) ? true : false ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment