移动端通常需要判断当前设备的类型,比如安卓,ios等。输出浏览器的请求代理,可以判断浏览器类型。js代码如下
判断当前浏览器的请求代理
我是出来玩的!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> </body> <script> // 复制代码扫描可以弹出你的机型 alert(navigator.userAgent) //判断手机系统 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { phoneSystem = "ios"; alert("我是苹果") } else if (/(Android)/i.test(navigator.userAgent)) { phoneSystem = "Android"; alert("我是安卓") } else { phoneSystem = "other"; } </script> </html>