判断微信内置浏览器进行跳转

    今天接到一个客户,人家是一个微信公众号的程序,也需要其他浏览器访问,就造成一个问题:

         微信客户端内置浏览器进行付款时候,会自动关闭上个页面,而用其他浏览器,比如UC浏览器等就无法跳转到微信进行付款,找了微信公众平台开发文档,总算找到眉目。

      微信内置浏览器的UA是:

/MicroMessenger/i

  所以我们可以写一个判断了

   

<script type="text/javascript">    
         
                var sUserAgent = navigator.userAgent.toLowerCase();    
                var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";    
                var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";    
                var bIsMidp = sUserAgent.match(/midp/i) == "midp";    
                var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";    
                var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";    
                var bIsAndroid = sUserAgent.match(/android/i) == "android";    
                var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";    
                var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
				var bIsWX = sUserAgent.match(/MicroMessenger/i) == "micromessenger";
                if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM ){    
                    window.location.href="weixin://";  
                }   
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					return true;
				}
				
</script>  

  

posted @ 2018-03-12 23:49  圆柱模板  阅读(1269)  评论(0编辑  收藏  举报