码迷,mamicode.com
首页 > 移动开发 > 详细

js判断PC端和移动端

时间:2015-08-20 14:47:41      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

var sUserAgent = window.navigator.userAgent.toLowerCase();//获取浏览器信息

var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; //ipad
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";//iphone

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";//ucweb浏览器

var bIsAndroid = sUserAgent.match(/android/i) == "android";//android

var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; //windows ce移动系统

var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";//windows mobile

 

if(bIsIpad){  //如果是IPAD端页面地址指向
  var sUrl = location.href;
if(!bForcepc){
  window.location.href = "ipad";
}
}
if(bIsIphoneOs || bIsAndroid){
var sUrl = location.href;
if(!bForcepc){
window.location.href = "smart";
}
}
if(bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM){
var sUrl = location.href;
if(!bForcepc){
window.location.href = "m";
}
}
}
function fGetQuery(name){//获取参数值
var sUrl = window.location.search.substr(1);
var r = sUrl.match(new RegExp("(^|&)" + name + "=([^&]*)(&|$)"));
return (r == null ? null : (r[2]));
}
function fShowVerBlock(){
if(bForcepc){
document.getElementByIdx_x("dv_block").style.display = "block";
}
else{
document.getElementByIdx_x("ad_block").style.display = "block";
}
}

 

js判断PC端和移动端

标签:

原文地址:http://www.cnblogs.com/maixi/p/4744897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!