【微信开发】JS和PHP分别判断当前浏览器是否微信浏览器
1、PHP端
//判断是否微信浏览器 -xzz1125 function is_weixin() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { return true; } return false; }
2、JS端
<script type="text/javascript"> window.onload = function(){ if(isWeiXin()){ //document.getElementById('baoming').href="http://www.xxiangfang.com/index.php?do=xian&view=index&join=phone"; //试睡师 document.getElementById('baoming').href="http://www.xxiangfang.com/index.php?do=zhaoguan&view=SelectCate"; //乡贤报名 } else{ //document.getElementById('baoming').href="http://www.xxiangfang.com/index.php?do=xian&view=index"; //试睡师 document.getElementById('baoming').href="http://www.xxiangfang.com/index.php?do=zhaoguan&view=SelectCate";//乡贤报名 } } function isWeiXin(){ var ua = window.navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i) == 'micromessenger'){ return true; }else{ return false; } } </script>