js判断设备类型

js判断设备类型:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>responsive demo</title>
  <script src="device.js"></script>
</head>
<body style="margin: auto; position: absolute; width:100%; height: 100%">
<script>
      var isMobile = device.mobile(),
            isTable = device.tablet();

       if(isMobile || isTable){
             window.open("m.html","_self");
       } else{
         window.open("pc.html","_self");
       }
</script>
</body>
</html>

 

当然,也可以用device.js来逐个检测设备。

 

javascript方法如下:

DeviceJavaScript Method
Mobiledevice.mobile()
Tabletdevice.tablet()
iOSdevice.ios()
iPaddevice.ipad()
iPhonedevice.iphone()
iPoddevice.ipod()
Androiddevice.android()
Android Phonedevice.androidPhone()
Android Tabletdevice.androidTablet()
BlackBerrydevice.blackberry()
BlackBerry Phonedevice.blackberryPhone()
BlackBerry Tabletdevice.blackberryTablet()
Windowsdevice.windows()
Windows Phonedevice.windowsPhone()
Windows Tabletdevice.windowsTablet()
Firefox OSdevice.fxos()
Firefox OS Phonedevice.fxosPhone()
Firefox OS Tabletdevice.fxosTablet()
MeeGodevice.meego()

比如可以用如下代码来检测设备是否为IOS设备

var isIPhone = device.iphone(),

      isIPad = device.ipad();

var isIOS = isIPhone  || isIPad;

if(isIOS){

        alert("is this iOS?"+isIOS);

}

或者可以用来控制当为mobile或者tablet的时候加载m.css, PC的时候加载pc.css

if(isMobile | isTable){

        document.write( ' <link rel="stylesheet" href="m.css">');

}else{

        document.write('<link rel="stylesheet" href="pc.css">');

}

参考链接:

https://github.com/matthewhudson/device.js

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值