js判断移动端与pc端

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

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


示例:
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()

时间: 2024-12-17 17:30:08

js判断移动端与pc端的相关文章

JS判断手机端还是pc端

如何判断页面是在移动端还是PC端打开的呢 window.location.href = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" : "http://news.baidu.com/";

使用js判断手机端和pc端浏览器内核

<span style="font-size:24px;color:#ff0000;">手机端:</span> <span style="font-size:14px;color:#339999;">//判断浏览器 var browser = { versions : function() { var u = navigator.userAgent, app = navigator.appVersion; return { tri

js判断当前浏览器是pc端还是移动端

根据用户的访问设备的不同来显示不同的页面样式,主要是判断移动设备还是电脑浏览器访问的. 下面给出js判断处理代码,以作参考. 1 <script type="text/javascript"> 2 function browserRedirect() { 3 var sUserAgent = navigator.userAgent.toLowerCase(); 4 var bIsIpad = sUserAgent.match(/ipad/i) == "ipad&q

js判断是手机还是PC端

有时接触一些手机上的适应,需要知道是pc 还是移动端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v

js 判断移动设备、pc端、android、iPhone、是否为微信、微博、qq空间

var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { //移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1,

JS判断手机端和PC端自动跳转

<script type="text/javascript"> function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone

js判断游览器是移动端还是PC端

js判断网页游览器是移动端还是PC端 1 <script type="text/javascript"> 2 function browserRedirect() { 3 var sUserAgent = navigator.userAgent.toLowerCase(); 4 var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; 5 var bIsIphoneOs = sUserAgent.match(/

js判断是移动端还是pc端

运行页面的时候,执行到js会判断来自于移动端还是pc端,如果是移动端则跳转制定链接地址,这样在手机端会有额外的不必要浪费的加载时间 var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto')

js判断移动端还是PC端

function isMobile(){ var sUserAgent= navigator.userAgent.toLowerCase(), bIsIpad= sUserAgent.match(/ipad/i) == "ipad", bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os", bIsMidp= sUserAgent.match(/midp/i) == "midp", b

js判断移动端或是pc端

Js判断客户端是否为PC还是手持移动设备方法一 function IsPC(){ var userAgentInfo = navigator.userAgent; var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var flag = true; for (