ylsunyuan技术论坛
标题:
JS判断浏览器是否为移动端
[打印本页]
作者:
sun
时间:
2016-4-29 23:07
标题:
JS判断浏览器是否为移动端
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>手机首页</title>
</head>
<body>
<h1>手机首页</h1><hr>
<script>
if(navigator.platform.indexOf('Win32')!=-1){
//pc
document.write("PC");
}else{
//shouji
//window.location.href="手机网址";
document.write("Phone");
}
</script>
<!-- 判断移动终端 -->
<script type="text/javascript">
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++){
if (browser.indexOf(mobileAgent[i])!=-1){
isMobile = true;
alert(mobileAgent[i]);
//location.href = '手机网址';
break;
}
}
</script>
</body>
</html>
复制代码
欢迎光临 ylsunyuan技术论坛 (http://bbs.ylsunyuan.com/)
Powered by Discuz! X3.2