您的位置:首页 > 运维架构 > 网站架构

JavaScript选择打开手机网站还是电脑网站

2015-01-28 14:14 309 查看
现在手机网站越来越普遍,类似京东、淘宝、新浪等等大家都推出了wap版,一种简单的方法判断,JavaScript选择打开手机网站还是电脑网站,如果是手机网站就让网页跳转到手机网址。如果是电脑网站,打开电脑网站。

<!DOCTYPE html>
<head>
<meta charset=utf-8>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript选择打开手机网站还是电脑网站</title>
<link rel="stylesheet" type="text/css" href="css/base.css" />
<script type="text/javascript">
if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)){
window.location.href='手机网站网址';
}else{
window.location.href='电脑网站网址';
}
</script>
</head>

<body>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: