function loadCSS() {
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
document.write('<link href="css/notpc.css" rel="stylesheet" type="text/css" media="screen" />')
}
else {
document.write('<link href="css/pc.css" rel="stylesheet" type="text/css" media="screen" />')
}
}
loadCSS()
把里面手机部分关键字删除。还有种办法就是判断屏幕宽度。
给你一个例子,有这个就好办了。不会可参考“JS 判断浏览器客户端类型”
<script type="text/javascript">var bForcepc = fGetQuery("dv") == "pc"//PC端
function fBrowserRedirect(){
var sUserAgent = 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){
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"
}
}
fBrowserRedirect()
</script>