首页 > 移动平台 > 详细

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

时间:2018-02-05 18:03:07      阅读:208      评论:0      收藏:0      [点我收藏+]

使用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(笔记)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!