js判断移动端与pc端

时间秒杀一切 提交于 2020-01-04 17:31:32

js判断移动端与pc端

 

这里介绍下使用device.js插件来判断移动端设备

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

示例:
1
2
3
4
5
6
7
if(device.mobile()){
    window.location.href = "移动端地址";
        //alert("移动端");
else {
       window.location.href = "PC端地址";
        //alert("PC端");
}

  

 

更多设备判断如下表格:

 

Device JavaScript Method
Mobile device.mobile()
Tablet device.tablet()
Desktop device.desktop()
iOS device.ios()
iPad device.ipad()
iPhone device.iphone()
iPod device.ipod()
Android device.android()
Android Phone device.androidPhone()
Android Tablet device.androidTablet()
BlackBerry device.blackberry()
BlackBerry Phone device.blackberryPhone()
BlackBerry Tablet device.blackberryTablet()
Windows device.windows()
Windows Phone device.windowsPhone()
Windows Tablet device.windowsTablet()
Firefox OS device.fxos()
Firefox OS Phone device.fxosPhone()
Firefox OS Tablet device.fxosTablet()
MeeGo device.meego()
Television device.television()

 

 

使用后device.js会在你的html节点上追加相应的设备样式

 

Device

CSS Classes

iPad ios ipad tablet
iPhone ios iphone mobile
iPod ios ipod mobile
Android Phone android mobile
Android Tablet android tablet
BlackBerry Phone blackberry mobile
BlackBerry Tablet blackberry tablet
Windows Phone windows mobile
Windows Tablet windows tablet
Firefox OS Phone fxos mobile
Firefox OS Tablet fxos tablet
MeeGo meego
Desktop desktop
Television television

 

移动端设备方向判断

 

Orientation JavaScript Method
Landscape device.landscape()
Portrait

device.portrait()

这里介绍下使用device.js插件来判断移动端设备

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

示例:
1
2
3
4
5
6
7
if(device.mobile()){
    window.location.href = "移动端地址";
        //alert("移动端");
else {
       window.location.href = "PC端地址";
        //alert("PC端");
}

  

 

更多设备判断如下表格:

 

Device JavaScript Method
Mobile device.mobile()
Tablet device.tablet()
Desktop device.desktop()
iOS device.ios()
iPad device.ipad()
iPhone device.iphone()
iPod device.ipod()
Android device.android()
Android Phone device.androidPhone()
Android Tablet device.androidTablet()
BlackBerry device.blackberry()
BlackBerry Phone device.blackberryPhone()
BlackBerry Tablet device.blackberryTablet()
Windows device.windows()
Windows Phone device.windowsPhone()
Windows Tablet device.windowsTablet()
Firefox OS device.fxos()
Firefox OS Phone device.fxosPhone()
Firefox OS Tablet device.fxosTablet()
MeeGo device.meego()
Television device.television()

 

 

使用后device.js会在你的html节点上追加相应的设备样式

 

Device

CSS Classes

iPad ios ipad tablet
iPhone ios iphone mobile
iPod ios ipod mobile
Android Phone android mobile
Android Tablet android tablet
BlackBerry Phone blackberry mobile
BlackBerry Tablet blackberry tablet
Windows Phone windows mobile
Windows Tablet windows tablet
Firefox OS Phone fxos mobile
Firefox OS Tablet fxos tablet
MeeGo meego
Desktop desktop
Television television

 

移动端设备方向判断

 

Orientation JavaScript Method
Landscape device.landscape()
Portrait

device.portrait()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!