js判断手机端操作系统(Andorid/IOS)

时间:2022-06-01 13:00:24
非常实用的js判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面
androidURL = "http://xxx/xxx.apk"; var browser = {
versions: function() {
var u = navigator.userAgent,
app = navigator.appVersion;
return { android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, iPhone: u.indexOf('iPhone') > -1 , iPad: u.indexOf('iPad') > -1,
iPod: u.indexOf('iPod') > -1, };
} (),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if (browser.versions.iPhone||browser.versions.iPad||browser.versions.iPod)
{
//如果是ios系統,直接跳轉至appstore該應用首頁,傳遞参數为該應用在appstroe的id號
window.location.href="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=123456";
}
else if(browser.versions.android)
{
window.location.href = androidURL;
}

转载请注明(B5教程网)原文链接:http://www.bcty365.com/content-69-1807-1.html

第二种方案:

<script language="javascript">
window.onload = function () {
alert("1");
var u = navigator.userAgent;
  document.write(typeof(navigator.platform)=="undefined"?"":navigator.platform)//输出对应的手机系统
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
alert("安卓手机");
// window.location.href = "mobile/index.html";
} else if (u.indexOf('iPhone') > -1) {//苹果手机
// window.location.href = "mobile/index.html";
alert("苹果手机");
} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
alert("winphone手机");
// window.location.href = "mobile/index.html";
}
}
</script>

原文地址:http://www.cnblogs.com/lyl6796910/p/3700151.html