- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>mobile-pc</title>
- <script type="text/javascript">
- function getuser(){
- var scan = navigator.userAgent;
- document.write(scan);
- if(scan.indexOf("Mobile") > -1)
- return "mobile";
- else if(scan.indexOf("Andriod") > -1 || scan.indexOf("Linux") > -1)
- return "andriod";
- else if(scan.indexOf("iPhone") > -1 || scan.indexOf("Mac") > -1)
- return "iphone";
- else if(scan.indexOf("iPad") > -1)
- return "ipad";
- else
- return "pc";
- }
- </script>
- </head>
- <body>
- <script type="text/javascript">
- var bres = getuser();
- if(bres == "mobile" || bres == "andriod" || bres == "iphone" || bres == "ipad")
- document.write("<br />"+"mobile");
- //window.location = "/mobile/home.html";
- else if(bres == "pc")
- document.write("<br />"+"pc");
- //window.location = "/pc/home.html";
- </script>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/0508201614909.html
来源: http://www.codesnippet.cn/detail/0508201614909.html