js判断手机浏览器操作系统和微信浏览器的方法
更新时间:2016年04月30日 12:56:19 投稿:mdxy-dxy
做手机端的前端开发,少不了对手机平台的判断。如,对于app下载,就要判断在Android平台下就显示Android下载提示;在iOS平台下就显示iOS下载提示
今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法:
<script type="text/javascript">
//手机端判断各个平台浏览器及操作系统平台
function checkPlatform(){
if(/android/i.test(navigator.userAgent)){
document.write("This is Android'browser.");//这是Android平台下浏览器
}
if(/(iPhoneiPadiPodiOS)/i.test(navigator.userAgent)){
document.write("This is iOS'browser.");//这是iOS平台下浏览器
}
if(/Linux/i.test(navigator.userAgent)){
document.write("This is Linux'browser.");//这是Linux平台下浏览器
}
if(/Linux/i.test(navigator.platform)){
document.write("This is Linux operating system.");//这是Linux操作系统平台
}
if(/MicroMessenger/i.test(navigator.userAgent)){
document.write("This is MicroMessenger'browser.");//这是微信平台下浏览器
}
}
$(document).ready(function(){
alert(navigator.platform);
checkPlatform();
});
</script>
注意上面的代码使用了jquery。需要加载jquery才可以运行。当然你可以把触发函数给删除了
在这里就不做pc端操作系统平台的判断了,怎么判断也说下方法,如用document.write(navigator.platform);就可以获得操作系统平台。在win32下就会显示Win32,;在Win64下就会显示Win64等。
下面脚本之家小编为大家补充几个不错的函数
<script type="text/javascript">
var browser = {
versions : function () {
var u = navigator.userAgent,
app = navigator.appVersion;
return {
trident : u.indexOf('Trident') > -1,
presto : u.indexOf('Presto') > -1,
webKit : u.indexOf('AppleWebKit') > -1,
gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
iPad : u.indexOf('iPad') > -1,
webApp : u.indexOf('Safari') == -1,
QQbrw : u.indexOf('MQQBrowser') > -1,
weiXin : u.indexOf('MicroMessenger') > -1,
ucLowEnd : u.indexOf('UCWEB7.') > -1,
ucSpecial : u.indexOf('rv:1.2.3.4') > -1,
ucweb : function () {
try {
return parseFloat(u.match(/ucweb\d+\.\d+/gi).toString().match(/\d+\.\d+/).toString()) >= 8.2
} catch (e) {
if (u.indexOf('UC') > -1) {
return true;
} else {
return false;
}
}
}
(),
Symbian : u.indexOf('Symbian') > -1,
ucSB : u.indexOf('Firefox/1.') > -1
};
}
()
}
if (browser.versions.QQbrw){
document.write("qq浏览器");
}else
{
document.write("其它浏览器");
}
</script>
亲测,非常好用。
相关文章
Highcharts 非常实用的Javascript统计图demo示例
官网实例中给出了各式各样的demo,可以参照document修改自己需要的即可,本文实现的是一个学生成绩走势demo,有需求的朋友可以参考下哈,希望对大家有所帮助2013-07-07
JavaScript判断字符长度、数字、Email、电话等常用判断函数分享
这篇文章主要介绍了JavaScript判断字符长度、数字、Email、电话等常用判断函数分享,本文直接给出实现代码,需要的朋友可以参考下2015-04-04
Firefox getBoxObjectFor getBoundingClientRect联系
Firefox在含有flash的网页上提示:不建议使用 getBoxObjectFor() 。 请使用 element.getBoundingClientRect()。2008-10-10
小程序按钮避免多次调用接口和点击方案实现(不用showLoading)
这篇文章主要介绍了小程序按钮避免多次调用接口和点击方案实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-04-04


最新评论