码迷,mamicode.com
首页 > 移动开发 > 详细

js判断操作系统windows,ios,android(笔记)

时间:2018-02-05 18:40:14      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:intel   获取   nav   gen   class   use   log   roi   body   

使用JS判断用户使用的系统是利用浏览器的userAgent。

 navigator.userAgent:userAgent 获取了浏览器用于 HTTP 请求的用户代理头的值。
 navigator.platform:platform        获取运行浏览器的操作系统和(或)硬件平台。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
var u = navigator.userAgent;
var iswindows = (u.indexOf("Windows",0) != -1)?1:0;  
var ismac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
var isAndroid = u.indexOf(Android) > -1 || u.indexOf(Adr) > -1; 
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); 
if (isAndroid==true)
{
    self.location=‘‘;     #重定向方法
}
if (isiOS==true)
{
    self.location=‘‘; 
}
if (iswindows==true)
{
    self.location=‘‘
}
if (ismac==true)
{
    self.location=‘‘
}
</script>
</head>
<body>
</body>
</html>

 

js判断操作系统windows,ios,android(笔记)

标签:intel   获取   nav   gen   class   use   log   roi   body   

原文地址:https://www.cnblogs.com/MrRead/p/8418512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!