Js 判断客户端是否为 PC 还是手持移动设备
方法一
[html]view plaincopy
1. functionIsPC(){
2. varuserAgentInfo=navigator.userAgent;
3. varAgents=newArray("Android","iPhone","SymbianOS","W
indowsPhone","iPad","iPod");
4. varflag=true;
5. for(varv=0;v<Agents.length;v++){
6. if(userAgentInfo.indexOf(Agents[v])>0){flag=fals
e;break;}
7. }
8. returnflag;
9. }
[html]view plaincopy
1. if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){
2. //alert(navigator.userAgent);
3. window.location.href="iPhone.html";
4. }elseif(/(Android)/i.test(navigator.userAgent)){
5. //alert(navigator.userAgent);
6. window.location.href="Android.html";
7. }else{
8. window.location.href="pc.html";
9. };
方法二
[html]view plaincopy
1. varbrowser={
2. versions:function(){
3. varu=navigator.userAgent,app=navigator.appVersi
on;
4. return{//移动终端浏览器版本信息
5. trident:u.indexOf('Trident')>-1,//IE 内核
6. presto:u.indexOf('Presto')>-1,//opera 内核
7. webKit:u.indexOf('AppleWebKit')>-1,//苹果、谷
歌内核
8. gecko:u.indexOf('Gecko')>-1&&u.indexOf('KHT
ML')==-1,//火狐内核
9. mobile:!!u.match(/AppleWebKit.*Mobile.*/),//是
否为移动终端
10. ios:!!u.match(/\(i[^;]+;(U;)?CPU.+MacOSX/),
//ios 终端
评论0