封装一个js获取window系统或者手机系统版本的方法
栏目: JavaScript · 发布时间: 7年前
内容简介:今天1024程序员的节日,祝广大程序猿朋友节日快乐!最近比较忙,疏于总结。博客很久没有详细好好的写文章了。今天这篇文章也是平时用到的。就是一个积累函数吧。后面有时间好好总结一下。navigator可以获取很多信息,我前面也有文章提及过,文章很简短,使用方式直接函数调用就可以了!
前言
今天1024 程序员 的节日,祝广大程序猿朋友节日快乐!最近比较忙,疏于总结。博客很久没有详细好好的写文章了。今天这篇文章也是平时用到的。就是一个积累函数吧。后面有时间好好总结一下。
通过navigator
navigator可以获取很多信息,我前面也有文章提及过, https://www.haorooms.com/post/js_navigator_bb
获取系统版本函数
// 获取系统版本
export function getOsVersion() {
var u = navigator.userAgent, version = ''
if (u.indexOf('Mac OS X') > -1) {
// ios
var regStr_saf = /OS [\d._]*/gi
var verinfo = u.match(regStr_saf)
version = 'IOS' + (verinfo + '').replace(/[^0-9|_.]/ig, '').replace(/_/ig, '.')
} else if (u.indexOf('Android') > -1 ||
u.indexOf('Linux') > -1) {
// android
version = 'Android' + u.substr(u.indexOf('Android') + 8, u.indexOf(';', u.indexOf('Android')) - u.indexOf('Android') - 8)
} else if (u.indexOf('BB10') > -1) {
// 黑莓bb10系统
version = 'blackberry' + u.substr(u.indexOf('BB10') + 5, u.indexOf(';', u.indexOf('BB10')) - u.indexOf('BB10') - 5)
} else if (u.indexOf('IEMobile') > -1) {
// windows phone
version = 'winphone' + u.substr(u.indexOf('IEMobile') + 9, u.indexOf(';', u.indexOf('IEMobile')) - u.indexOf('IEMobile') - 9)
} else {
var userAgent = navigator.userAgent.toLowerCase()
if (userAgent.indexOf('windows nt 5.0') > -1) {
version = 'Windows 2000'
} else if (userAgent.indexOf('windows nt 5.1') > -1 || userAgent.indexOf('windows nt 5.2') > -1) {
version = 'Windows XP'
} else if (userAgent.indexOf('windows nt 6.0') > -1) {
version = 'Windows Vista'
} else if (userAgent.indexOf('windows nt 6.1') > -1 || userAgent.indexOf('windows 7') > -1) {
version = 'Windows 7'
} else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows 8') > -1) {
version = 'Windows 8'
} else if (userAgent.indexOf('windows nt 6.3') > -1) {
version = 'Windows 8.1'
} else if (userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows nt 10.0') > -1) {
version = 'Windows 10'
} else {
version = 'Unknown'
}
}
return version
}
文章很简短,使用方式直接函数调用就可以了!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 使用Spring和Hibernate的Java Logging系统进行封装
- Vue + Element-ui实现后台管理系统(4)---封装一个ECharts组件的一点思路
- 封装JDBC—非框架开发必备的封装类
- SpringBlade 2.3.2 发布,增加 OSS 封装及单元测试封装
- SpringBlade 2.3.2 发布,增加 OSS 封装及单元测试封装
- docker 封装 alinode
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++ Concurrency in Action
Anthony Williams / Manning Publications / 2012-2-28 / USD 69.99
HIGHLIGHT C++ Concurrency in Action is the first book to market to show how to take advantage of the new C++ Standard and how to write robust multi-threaded applications in C++. DESCRIPTION With ......一起来看看 《C++ Concurrency in Action》 这本书的介绍吧!