js区分移动设备与PC

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link type="text/css" rel="stylesheet" media="screen" href="http://mat1.gtimg.com/www/base/base.css" />
</head>
<body>
<!-- 区分移动端与PC端代码一 ipad属于移动端-->
<script type="text/javascript">
if (/iphone|nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|android|iPod|iPad/i.test(navigator.userAgent.toLowerCase())) {
//添加移动端代码(包含ipad、iphone等)
}else{
//添加pc代码
}
</script>

<!-- 区分移动端与PC端代码二 ipad属于PC端-->
<script type="text/javascript">
if (/iphone|nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|android|iPod/i.test(navigator.userAgent.toLowerCase())) {
//添加移动端代码(不包括IPAD)
}else{
//添加pc代码(包含ipad、iphone等)
}
</script>
</body>
</html>

 

posted @ 2014-05-14 14:53  寻一颗心  阅读(329)  评论(0编辑  收藏  举报