<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>跳轉判斷</title>
</head>
<body>
<div>
window.navigator.userAgent;該函數是用來檢測 用戶代理(即設備系統)的。
而後經過 match()方法來匹配 這個用戶代理是不是正則列出的某一個,若是是跳轉到移動端頁面,不然跳轉到pc端頁面
</div>
<script type="text/javascript">
function getBrowser(){ //判斷瀏覽器是在android系統上仍是在ios系統上
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
window.location.href = "web/index.html"; //移動端頁面
}else{
window.location.href="pc/index.html"; //pc端頁面
}
}
getBrowser();
</script>
</body>
</html>javascript