判断pc浏览器和手机浏览器方法
一
//平臺、設備和操作系統
??????? var system = {
??????????? win: false,
??????????? mac: false,
??????????? xll: false,
??????????? ipad:false
??????? };
??????? //檢測平臺
??????? var p = navigator.platform;
??????? system.win = p.indexOf("Win") == 0;
??????? system.mac = p.indexOf("Mac") == 0;
??????? system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
??????? system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
??????? //跳轉語句,如果是手機訪問就自動跳轉到wap.baidu.com頁面
??????? if (system.win || system.mac || system.xll||system.ipad) { ?
?? ??? ??? ?
??????? } else {
?? ??? ??? ?window.location.href = "http://www.baidu.com";
??????? }
二
??????? //平臺、設備和操作系統
??????? var system = {
??????????? win: false,
??????????? mac: false,
??????????? xll: false,
??????????? ipad:false
??????? };
??????? //檢測平臺
??????? var p = navigator.platform;
??????? system.win = p.indexOf("Win") == 0;
??????? system.mac = p.indexOf("Mac") == 0;
??????? system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
??????? system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
???????
??????? if (system.win || system.mac || system.xll||system.ipad) { ?
?? ??? ????
??????? } else {
?? ??? ??? ?var weixin =new is_weixn;
??????? }
??????? function is_weixn(){
?? ??? ???? var ua = navigator.userAgent.toLowerCase();
?? ??? ???? if(ua.match(/MicroMessenger/i)=="micromessenger") {
?? ??? ???????? return true;
?? ??? ???? } else {
?? ??? ??? ???? jQuery(document).ready(function($){
? ??? ??? ??? ???? login();
?? ??? ??? ???? })
?? ??? ???? }
?? ??? ?}
?? ???? function login(){
?? ??? ??? ?var obj = new WxLogin({
?? ??? ??? ??? ?id: "code",
?? ??? ??? ??? ?appid: appid,
?? ??? ??? ??? ?scope: "snsapi_login",
?? ??? ??? ??? ?redirect_uri: "http%3a%2f%2fwww.caiex.com%2fCAIEX-GAME%2floginController%2floginFallsGame.shtml%3fpageName%3d55",
?? ??? ??? ??? ?state: randomString(6),
?? ??? ??? ??? ?style: "black",
?? ??? ??? ??? ?href: ""
?? ??? ??? ?});
?? ??? ??? ?$('.theme-popover-mask').fadeIn(100);
?? ??? ??? ?$('.theme-popover').slideDown(200);
?? ??? ?}
?
轉載于:https://www.cnblogs.com/happiness-mumu/p/6023245.html
總結
以上是生活随笔為你收集整理的判断pc浏览器和手机浏览器方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: USACO 保护花朵 Protectin
- 下一篇: js原生捕鱼达人(一)