1 function isOpenMode(){ 2 //平台、设备和操作系统 3 var system = { 4 win: false, 5 mac: false, 6 xll: false, 7 ipad: false 8 }; 9 //检测平台 10 var p = navigator.platform; 11 system.win = p.indexOf("Win") == 0; 12 system.mac = p.indexOf("Mac") == 0; 13 system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); 14 system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false; 15 //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面 16 if (system.win || system.mac || system.xll || system.ipad) { 17 var ua = navigator.userAgent.toLowerCase(); 18 if(ua.match(/MicroMessenger/i)=="micromessenger") { 19 alert("在PC端微信上打开的"); 20 return 2; 21 } else { 22 alert("在PC端非微信上打开的"); 23 return 3; 24 } 25 } else { 26 var ua = navigator.userAgent.toLowerCase(); 27 if(ua.match(/MicroMessenger/i)=="micromessenger") { 28 alert("在手机端微信上打开的"); 29 return 1; 30 } else { 31 alert("在手机上非微信上打开的"); 32 return 4; 33 } 34 } 35 }