JavaScript选择打开手机网站还是电脑网站
现在手机网站越来越普遍,类似京东、淘宝、新浪等等大家都推出了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>

浙公网安备 33010602011771号