我想判断用户如果是IOS13系统就跳转www.baidu.com
如果是13系统以下,则跳转www.sogou.com
以下js是我百度到的获取IOS 系统版本号,该如何改一下,才能达到以上要求呢。
谢谢大佬们
<script type="text/javascript">
var str= navigator.userAgent.toLowerCase();
var ver=str.match(/cpu iphone os (.*?) like mac os/);
if(!ver){
alert("请在Ios系统中打开");
}else{
alert("你当前的Ios系统版本为:"+ver[1].replace(/_/g,"."));
}
</script>
新疆网友:
- var str= navigator.userAgent.toLowerCase();
- var ver=str.match(/cpu iphone os (.*?) like mac os/);
- // 如果是IOS用户
- if(ver) {
- // 获取版本号
- var version = parseInt(ver[1].substring(0, ver[1].indexOf(‘_’)));
- if(version == 13) {
- location.href = "www.baidu.com";
- }
- else {
- location.href = "www.sogou.com";
- }
- }
复制代码
海南网友:v=ver[1].replace(/_/g,".");
然后if判断v值 就行了
海南网友: var str= navigator.userAgent.toLowerCase();
var ver=str.match(/cpu iphone os (.*?) like mac os/);
v=ver[1].replace(/_/g,’.’);
if(v>=13.0){
alert(‘大于13系统了’);
}
else{
alert(’13系统以下了’);
}
运行的时候,不管是IOS12还是IOS13 ,都会 得到【13系统一下了】这个值
河南网友:你对比的是string吧
转为数字
江西网友:我只是告诉了你怎么写 具体的代码还是得自己写下。我手机上的不好码代码…
河北网友:或者直接对比string是不是13开头的就行了 不用转数字对比具体的大小
青海网友:谢谢,搞好了
未经允许不得转载:美国VPS_搬瓦工CN2 GIA VPS » 大虾帮忙写个看个js