<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>判断手机类型</title> </head> <body> //第一种方法 <script> window.onload = function () { var u = navigator.userAgent; if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机 alert("安卓手机"); // window.location.href = ""; } else if (u.indexOf('iPhone') > -1) {//苹果手机 // window.location.href = ""; alert("苹果手机"); } else if (u.indexOf('Windows Phone') > -1) {//winphone手机 alert("winphone手机") // window.location.href = ""; } } </script> //第二种方法 <script language="javascript"> var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test(ua)) { alert("iphone"); // window.location.href = "http://www.runoob.com/js/js-popup.html"; } else if (/android/.test(ua)) { // window.location.href = "https://www.baidu.com/"; alert("android"); } </script> </body> </html>