Home  >  Article  >  Web Front-end  >  How to use JavaScript to determine whether it is a WeChat scan code

How to use JavaScript to determine whether it is a WeChat scan code

巴扎黑
巴扎黑Original
2017-08-11 10:40:302814browse

This article introduces you to the JS method of judging whether it is a WeChat scan code through code. It is very good. Friends who need it can refer to it.

1. In the userAgent attribute of navagitor, judge whether Contains micromessenger

2. Code


/** 
 * 判断微信扫码 
 */ 
function isWechat() { 
  var ua = navigator.userAgent.toLowerCase(),flag = false; 
  // if(ua.match(/MicroMessenger/i) === "micromessenger"){ 
  if(ua.indexOf("micromessenger") > -1){ 
    flag = true; 
  }else { 
    flag = false; 
  } 
  return flag; 
}

The above is the detailed content of How to use JavaScript to determine whether it is a WeChat scan code. For more information, please follow other related articles on the PHP Chinese website!

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