js簡單判斷移動端系統(tǒng)的方法
更新時間:2016年02月25日 09:56:52 作者:小壞
這篇文章主要介紹了js簡單判斷移動端系統(tǒng)的方法,通過JavaScript的navigator.userAgent相關屬性判斷訪問端的系統(tǒng)類型,非常簡單實用,需要的朋友可以參考下
本文實例講述了js簡單判斷移動端系統(tǒng)的方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" >
<meta name="format-detection" content="telephone=no">
<title>Document</title>
</head>
<body>
<script>
var isMobile = {
Android : function() {
return navigator.userAgent.match(/Android/i) ? true : false;
},
BlackBerry : function() {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
},
iOS : function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
},
Windows : function() {
return navigator.userAgent.match(/IEMobile/i) ? true : false;
},
any : function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};
if (isMobile.iOS()) {
alert("apple");
} else {
alert("Android");
}
</script>
</body>
</html>
更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
相關文章
JavaScript數組中相同的元素進行分組(數據聚合)groupBy函數詳解
今天在打算從js端時序數據庫TSDB中,按相同的類型的數據排在一起,并且取同一時間段最新的數據,經過查詢這種思想叫做數據聚合,就是返回的數據要根據一個屬性來做計算,這篇文章主要介紹了JavaScript數組中相同的元素進行分組(數據聚合)?groupBy函數,需要的朋友可以參考下2023-12-12

