1.设备判断
首先在html中引入一个device.js库,然后使用内部的方法;
<!doctype html>
<html>
<head>
<meta charset="utf-8"></meta>
<title>设备检测</title>
<script type="text/javascript" src = "device.mini.js"></script>
<link id = "mylink" rel = "stylesheet" href = "css/1.css" type = "text/css"></link>
</head>
<body>
<h1 id = "device">设备</h1>
<script>
var device = document.getElementById("device");
//此部分为根据检测设备来更换css样式表;
if(device.mobile()){
device.innerHTML = "手机";
window.location="shouji.html"; /*页面跳转到手机页面*/
var mylink = document.getElementById("mylink");
mylink.href = "css/2.css";/*更换一个css样式*/
}else if(device.ipad()){
device.innerHTML = "pad";
}els {
device.innerHTML= "台式机";
}
//此部分为根据检测浏览器的宽度来更换css样式表,适用于应用不同分表率的台式机;
var docWidth = document.documentElement.clientWidth;
</script>
</body>
<html/>
注意:device.portrait() 检测设备是否是竖直的;
device.landscape() 检测设备是否是水平的;
device.mobile() 检测设备是否是手机;
device.ipad()
device.iphone()
device.android() 是否是安卓手机;
device.tablet() 是否是大屏手机(7寸以上);
首先在html中引入一个device.js库,然后使用内部的方法;
<!doctype html>
<html>
<head>
<meta charset="utf-8"></meta>
<title>设备检测</title>
<script type="text/javascript" src = "device.mini.js"></script>
<link id = "mylink" rel = "stylesheet" href = "css/1.css" type = "text/css"></link>
</head>
<body>
<h1 id = "device">设备</h1>
<script>
var device = document.getElementById("device");
//此部分为根据检测设备来更换css样式表;
if(device.mobile()){
device.innerHTML = "手机";
window.location="shouji.html"; /*页面跳转到手机页面*/
var mylink = document.getElementById("mylink");
mylink.href = "css/2.css";/*更换一个css样式*/
}else if(device.ipad()){
device.innerHTML = "pad";
}els {
device.innerHTML= "台式机";
}
//此部分为根据检测浏览器的宽度来更换css样式表,适用于应用不同分表率的台式机;
var docWidth = document.documentElement.clientWidth;
</script>
</body>
<html/>
注意:device.portrait() 检测设备是否是竖直的;
device.landscape() 检测设备是否是水平的;
device.mobile() 检测设备是否是手机;
device.ipad()
device.iphone()
device.android() 是否是安卓手机;
device.tablet() 是否是大屏手机(7寸以上);